Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/src/api/mutations/pin-to-blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function usePinToBlog(entry: Entry, onSuccess: () => void) {
const { activeUser, account } = useActiveAccount();
const qc = useQueryClient();

const { mutateAsync: updateProfile } = useUpdateProfile(account!);
const { mutateAsync: updateProfile } = useUpdateProfile(account ?? null);

return useMutation({
mutationKey: ["pinToBlog"],
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/api/mutations/update-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ import { useUpdateProfileMutation } from "@/api/sdk-mutations";
* This is a compatibility wrapper that maintains the old API while using SDK underneath.
* For new code, consider using `useUpdateProfileMutation` directly from SDK mutations.
*/
export function useUpdateProfile(account: FullAccount) {
export function useUpdateProfile(account: FullAccount | null) {
const { mutateAsync: sdkUpdateProfile } = useUpdateProfileMutation();

return useMutation({
mutationKey: ["update-profile", account.name],
mutationKey: ["update-profile", account?.name],
mutationFn: async ({ nextProfile }: { nextProfile: AccountProfile }) => {
if (!account) {
throw new Error("Account is not available");
}
// Use SDK mutation — handles cache update via buildProfileMetadata (proper deep merge)
await sdkUpdateProfile({
profile: nextProfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { FilterFriends } from "./filter-friends";
import { useDebounce } from "react-use";
import { FriendListItem } from "@/app/(dynamicPages)/profile/[username]/_components/friends/friend-list-item";
import { AnimatePresence, motion } from "framer-motion";
import type { Friend } from "./types";

const loadLimit = 30;

interface Props {
account: Account;
mode: string;
mode: "following" | "followers";
}

export const FriendsList = ({ account, mode }: Props) => {
Expand All @@ -28,7 +29,8 @@ export const FriendsList = ({ account, mode }: Props) => {
const {
data,
isFetching: isFriendsFetching,
fetchNextPage
fetchNextPage,
hasNextPage
} = useInfiniteQuery(
getFriendsInfiniteQueryOptions(account.name, mode, {
limit: loadLimit
Expand All @@ -46,40 +48,41 @@ export const FriendsList = ({ account, mode }: Props) => {
() => isFriendsFetching || isSearchFetching,
[isFriendsFetching, isSearchFetching]
);
const dataFlow = useMemo(
() =>
query
? searchData ?? []
: data?.pages
?.reduce((acc, page) => [...acc, ...page], [])
?.filter((item) => {
if (!type) {
return true;
}

const lastSeenTime = dayjs(item.active).toDate();
const timeDifference = new Date().getTime() - lastSeenTime.getTime();
const daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));
const yearsDifference = Math.ceil(daysDifference / 365);

return (
(type === FilterFriendsType.Recently && daysDifference < 7) ||
(type === FilterFriendsType.ThisMonth &&
daysDifference > 7 &&
daysDifference < 30) ||
(type === FilterFriendsType.ThisYear &&
daysDifference >= 30 &&
daysDifference < 360) ||
(type === FilterFriendsType.OneYear && daysDifference === 365) ||
(type === FilterFriendsType.MoreThanOneYear && yearsDifference > 1)
);
}) ?? [],
[data?.pages, query, searchData, type]
);
const hasMore = useMemo(
() => (data?.pages?.[data?.pages.length - 1]?.length ?? 0) >= loadLimit,
[data?.pages]
);

const dataFlow = useMemo((): Friend[] => {
const rawItems = query
? searchData ?? []
: data?.pages?.flat() ?? [];

const filtered = rawItems.filter((item) => {
if (!type) return true;

const lastSeenTime = dayjs(item.active).toDate();
const timeDifference = new Date().getTime() - lastSeenTime.getTime();
const daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));
Comment thread
feruzm marked this conversation as resolved.

return (
(type === FilterFriendsType.Recently && daysDifference <= 7) ||
(type === FilterFriendsType.ThisMonth &&
daysDifference > 7 &&
daysDifference <= 30) ||
(type === FilterFriendsType.ThisYear &&
daysDifference > 30 &&
daysDifference < 365) ||
(type === FilterFriendsType.OneYear &&
daysDifference >= 365 &&
daysDifference < 730) ||
(type === FilterFriendsType.MoreThanOneYear && daysDifference >= 730)
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});

return filtered.map((item) => ({
name: item.name,
reputation: item.reputation,
lastSeen: dayjs(item.active).fromNow()
}));
}, [data?.pages, query, searchData, type]);


useDebounce(
() => {
Expand Down Expand Up @@ -141,7 +144,7 @@ export const FriendsList = ({ account, mode }: Props) => {

{!query && dataFlow.length > 1 && (
<div className="load-more">
<Button disabled={isFetching || !hasMore} onClick={() => fetchNextPage()}>
<Button disabled={isFetching || !hasNextPage} onClick={() => fetchNextPage()}>
{i18next.t("g.load-more")}
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function Followers({ onHide, account }: Props) {
</ModalTitle>
</ModalHeader>
<ModalBody>
<FriendsList mode="follower" account={account} />
<FriendsList mode="followers" account={account} />
</ModalBody>
</Modal>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/features/shared/fragments/fragments-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function Fragments({ onPick, onAdd, onEdit }: Props) {
const items = useMemo(
() =>
allFragments
.filter((x) => x.title.toLowerCase().indexOf(searchQuery.toLowerCase()) !== -1)
.filter((x) => (x.title ?? "").toLowerCase().includes(searchQuery.toLowerCase()))
.sort((a, b) => (new Date(b.created).getTime() > new Date(a.created).getTime() ? 1 : -1)),
[allFragments, searchQuery]
);
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.0.3

### Patch Changes

- Fix: Friends active data (#656)

## 2.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ecency/sdk",
"private": false,
"version": "2.0.2",
"version": "2.0.3",
"description": "Ecency SDK",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/wallets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ecency/wallets

## 1.5.31

### Patch Changes

- Updated dependencies []:
- @ecency/sdk@2.0.3

## 1.5.30

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ecency/wallets",
"private": false,
"version": "1.5.30",
"version": "1.5.31",
"description": "Ecency wallets",
"repository": {
"type": "git",
Expand Down