Skip to content

Commit

Permalink
🌺 Lens and Hey v3: v41 (#lens-v3)
Browse files Browse the repository at this point in the history
Summary: Migrated to Lens v3, updating types and cache operations.

Highlights:

• Replaced `operations` field with `LoggedInPostOperations` in cache updates.
• Removed `getLennyURL` and related error handling for avatar images.
• Updated `getCollectModuleData` to use new `SimpleCollectActionSettings` type.

Read more: https://pierre.co/hey/hey/lens-v3
  • Loading branch information
Yoginth authored and Pierre committed Dec 7, 2024
1 parent 3e5c998 commit c44d649
Show file tree
Hide file tree
Showing 34 changed files with 107 additions and 380 deletions.
53 changes: 0 additions & 53 deletions apps/api/src/routes/avatar.ts

This file was deleted.

37 changes: 0 additions & 37 deletions apps/api/tests/avatar.spec.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/web/src/components/Account/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import getAccount from "@hey/helpers/getAccount";
import getAccountAttribute from "@hey/helpers/getAccountAttribute";
import getAvatar from "@hey/helpers/getAvatar";
import getFavicon from "@hey/helpers/getFavicon";
import getLennyURL from "@hey/helpers/getLennyURL";
import getMentions from "@hey/helpers/getMentions";
import type { Account } from "@hey/indexer";
import { Button, Drawer, H3, Image, LightBox, Tooltip } from "@hey/ui";
Expand Down Expand Up @@ -73,9 +72,6 @@ const Details: FC<DetailsProps> = ({ isSuspended = false, account }) => {
className="size-32 cursor-pointer rounded-full bg-gray-200 ring-8 ring-gray-50 sm:size-52 dark:bg-gray-700 dark:ring-black"
height={128}
onClick={() => setExpandedImage(getAvatar(account, EXPANDED_AVATAR))}
onError={({ currentTarget }) => {
currentTarget.src = getLennyURL(account.address);
}}
src={getAvatar(account)}
width={128}
/>
Expand Down
4 changes: 0 additions & 4 deletions apps/web/src/components/Composer/NewPost.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import getAvatar from "@hey/helpers/getAvatar";
import getLennyURL from "@hey/helpers/getLennyURL";
import { Card, Image } from "@hey/ui";
import { useRouter } from "next/router";
import type { FC } from "react";
Expand Down Expand Up @@ -60,9 +59,6 @@ const NewPost: FC<NewPostProps> = ({ tags }) => {
alt={currentAccount?.address}
className="size-11 cursor-pointer rounded-full border bg-gray-200 dark:border-gray-700"
height={44}
onError={({ currentTarget }) => {
currentTarget.src = getLennyURL(currentAccount?.address);
}}
src={getAvatar(currentAccount)}
width={44}
/>
Expand Down
13 changes: 2 additions & 11 deletions apps/web/src/components/Composer/NewPublication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Errors } from "@hey/data/errors";
import collectModuleParams from "@hey/helpers/collectModuleParams";
import getAccount from "@hey/helpers/getAccount";
import getMentions from "@hey/helpers/getMentions";
import type { Post, PostResponse } from "@hey/indexer";
import type { Post } from "@hey/indexer";
import type { IGif } from "@hey/types/giphy";
import type { NewAttachment } from "@hey/types/misc";
import { Button, Card, H6 } from "@hey/ui";
Expand Down Expand Up @@ -153,18 +153,9 @@ const NewPublication: FC<NewPublicationProps> = ({ className, post }) => {
errorToast(error);
};

const onCompleted = (post?: PostResponse) => {
if (post?.__typename !== "PostResponse") {
return onError();
}

// Reset states
reset();
};

const { createPost } = useCreatePost({
commentOn: post,
onCompleted,
onCompleted: () => reset(),
onError,
quoteOf: quotedPost as Post
});
Expand Down
9 changes: 1 addition & 8 deletions apps/web/src/components/Notification/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import Verified from "@components/Shared/Account/Icons/Verified";
import AccountPreview from "@components/Shared/AccountPreview";
import getAccount from "@hey/helpers/getAccount";
import getAvatar from "@hey/helpers/getAvatar";
import getLennyURL from "@hey/helpers/getLennyURL";
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import type { Account } from "@hey/indexer";
import { Image } from "@hey/ui";
import Link from "next/link";
import type { FC, SyntheticEvent } from "react";
import type { FC } from "react";

interface NotificationProfileProps {
account: Account;
Expand All @@ -17,11 +16,6 @@ interface NotificationProfileProps {
export const NotificationAccountAvatar: FC<NotificationProfileProps> = ({
account
}) => {
const handleImageError = (event: SyntheticEvent<HTMLImageElement>) => {
const target = event.currentTarget;
target.src = getLennyURL(account.address);
};

return (
<AccountPreview
handle={account.username?.localName}
Expand All @@ -36,7 +30,6 @@ export const NotificationAccountAvatar: FC<NotificationProfileProps> = ({
alt={account.address}
className="size-7 rounded-full border bg-gray-200 sm:size-8 dark:border-gray-700"
height={32}
onError={handleImageError}
src={getAvatar(account)}
width={32}
/>
Expand Down
13 changes: 3 additions & 10 deletions apps/web/src/components/Post/Actions/Like.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HeartIcon as HeartIconSolid } from "@heroicons/react/24/solid";
import { Errors } from "@hey/data/errors";
import nFormatter from "@hey/helpers/nFormatter";
import {
type LoggedInPostOperations,
type Post,
PostReactionType,
useAddReactionMutation,
Expand Down Expand Up @@ -34,16 +35,8 @@ const Like: FC<LikeProps> = ({ post, showCount }) => {

const updateCache = (cache: ApolloCache<any>) => {
cache.modify({
fields: {
operations: (existingValue) => {
return {
...existingValue,
// TODO: This is a hack to make the cache update
'hasReacted({"request":{"type":"UPVOTE"}})': !hasReacted
};
}
},
id: cache.identify(post)
fields: { hasReacted: () => !hasReacted },
id: cache.identify(post.operations as LoggedInPostOperations)
});
cache.modify({
fields: {
Expand Down
9 changes: 3 additions & 6 deletions apps/web/src/components/Post/Actions/Menu/Bookmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BookmarkIcon as BookmarkIconOutline } from "@heroicons/react/24/outline
import { BookmarkIcon as BookmarkIconSolid } from "@heroicons/react/24/solid";
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import {
type LoggedInPostOperations,
type Post,
useBookmarkPostMutation,
useUndoBookmarkPostMutation
Expand All @@ -30,12 +31,8 @@ const Bookmark: FC<BookmarkProps> = ({ post }) => {

const updateCache = (cache: ApolloCache<any>) => {
cache.modify({
fields: {
operations: (existingValue) => {
return { ...existingValue, hasBookmarked: !hasBookmarked };
}
},
id: cache.identify(post)
fields: { hasBookmarked: () => !hasBookmarked },
id: cache.identify(post.operations as LoggedInPostOperations)
});
cache.modify({
fields: {
Expand Down
10 changes: 3 additions & 7 deletions apps/web/src/components/Post/Actions/Menu/NotInterested.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MenuItem } from "@headlessui/react";
import errorToast from "@helpers/errorToast";
import { EyeIcon, EyeSlashIcon } from "@heroicons/react/24/outline";
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import type { Post } from "@hey/indexer";
import type { LoggedInPostOperations, Post } from "@hey/indexer";
import cn from "@hey/ui/cn";
import type { FC } from "react";
import { toast } from "react-hot-toast";
Expand All @@ -21,12 +21,8 @@ const NotInterested: FC<NotInterestedProps> = ({ post }) => {

const updateCache = (cache: ApolloCache<any>, notInterested: boolean) => {
cache.modify({
fields: {
operations: (existingValue) => {
return { ...existingValue, isNotInterested: notInterested };
}
},
id: cache.identify(post)
fields: { isNotInterested: () => !notInterested },
id: cache.identify(post.operations as LoggedInPostOperations)
});
};

Expand Down
17 changes: 11 additions & 6 deletions apps/web/src/components/Post/Actions/Share/Repost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { ArrowsRightLeftIcon } from "@heroicons/react/24/outline";
import { Errors } from "@hey/data/errors";
import selfFundedTransactionData from "@hey/helpers/selfFundedTransactionData";
import sponsoredTransactionData from "@hey/helpers/sponsoredTransactionData";
import { type Post, TriStateValue, useRepostMutation } from "@hey/indexer";
import {
type LoggedInPostOperations,
type Post,
TriStateValue,
useRepostMutation
} from "@hey/indexer";
import { OptmisticPostType } from "@hey/types/enums";
import type { OptimisticTransaction } from "@hey/types/misc";
import cn from "@hey/ui/cn";
Expand Down Expand Up @@ -52,14 +57,14 @@ const Repost: FC<RepostProps> = ({ isLoading, post, setIsLoading }) => {
const updateCache = () => {
cache.modify({
fields: {
operations: (existingValue) => {
return { ...existingValue, hasMirrored: true };
hasReposted: (existingValue) => {
return { ...existingValue, optimistic: true };
}
},
id: cache.identify(post)
id: cache.identify(post.operations as LoggedInPostOperations)
});
cache.modify({
fields: { mirrors: () => shares + 1 },
fields: { reposts: () => shares + 1 },
id: cache.identify(post.stats)
});
};
Expand All @@ -69,7 +74,7 @@ const Repost: FC<RepostProps> = ({ isLoading, post, setIsLoading }) => {
increment();
updateCache();
addTransaction(generateOptimisticRepost({ txHash: hash }));
toast.success("Post has been mirrored!");
toast.success("Post has been reposted!");
};

const onError = (error: any) => {
Expand Down
4 changes: 1 addition & 3 deletions apps/web/src/components/Post/Actions/Share/UndoRepost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const UndoRepost: FC<UndoRepostProps> = ({ isLoading, post, setIsLoading }) => {
fields: { reposts: () => targetPost.stats.reposts - 1 },
id: cache.identify(targetPost.stats)
});
cache.evict({
id: `${post?.__typename}:${post?.id}`
});
cache.evict({ id: cache.identify(post) });
};

const onError = (error?: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import getCurrentSession from "@helpers/getCurrentSession";
import { Errors } from "@hey/data/errors";
import getCollectModuleData from "@hey/helpers/getCollectModuleData";
import getPostActionActOnKey from "@hey/helpers/getPostActionActOnKey";
import type { AnyPost, PostAction } from "@hey/indexer";
import type { Post, PostAction } from "@hey/indexer";
import { OptmisticPostType } from "@hey/types/enums";
import type { OptimisticTransaction } from "@hey/types/misc";
import { Button, WarningMessage } from "@hey/ui";
Expand All @@ -29,7 +29,7 @@ interface CollectActionProps {
noBalanceErrorMessages?: ReactNode;
onCollectSuccess?: () => void;
postAction: PostAction;
post: AnyPost;
post: Post;
}

const CollectAction: FC<CollectActionProps> = ({
Expand Down
12 changes: 9 additions & 3 deletions apps/web/src/components/Post/OpenAction/CollectModule/Splits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import formatAddress from "@hey/helpers/formatAddress";
import getAccount from "@hey/helpers/getAccount";
import getAvatar from "@hey/helpers/getAvatar";
import getStampFyiURL from "@hey/helpers/getStampFyiURL";
import { useAccountsQuery, type Account } from "@hey/indexer";
import {
type Account,
type RecipientDataOutput,
useAccountsQuery
} from "@hey/indexer";
import { Image } from "@hey/ui";
import Link from "next/link";
import type { FC } from "react";
Expand Down Expand Up @@ -77,8 +81,10 @@ const Splits: FC<SplitsProps> = ({ recipients }) => {
src={account ? getAvatar(account) : getStampFyiURL(address)}
/>
{account ? (
<Link href={getAccount(account).link}>
<Slug slug={getAccount(account).slugWithPrefix} />
<Link href={getAccount(account as Account).link}>
<Slug
slug={getAccount(account as Account).slugWithPrefix}
/>
</Link>
) : (
<Link
Expand Down
4 changes: 0 additions & 4 deletions apps/web/src/components/Post/PostAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import getAccount from "@hey/helpers/getAccount";
import getAvatar from "@hey/helpers/getAvatar";
import getLennyURL from "@hey/helpers/getLennyURL";
import { isRepost } from "@hey/helpers/postHelpers";
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import type { AnyPost, TimelineItem } from "@hey/indexer";
Expand Down Expand Up @@ -42,9 +41,6 @@ const PostAvatar: FC<PostAvatarProps> = ({
height={quoted ? 25 : 44}
loading="lazy"
onClick={() => push(getAccount(account).link)}
onError={({ currentTarget }) => {
currentTarget.src = getLennyURL(account.address);
}}
src={getAvatar(account)}
width={quoted ? 25 : 44}
/>
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/components/Shared/Account/Follow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import errorToast from "@helpers/errorToast";
import { Errors } from "@hey/data/errors";
import selfFundedTransactionData from "@hey/helpers/selfFundedTransactionData";
import sponsoredTransactionData from "@hey/helpers/sponsoredTransactionData";
import { type Account, useFollowMutation } from "@hey/indexer";
import {
type Account,
type LoggedInAccountOperations,
useFollowMutation
} from "@hey/indexer";
import { OptmisticPostType } from "@hey/types/enums";
import type { OptimisticTransaction } from "@hey/types/misc";
import { Button } from "@hey/ui";
Expand Down Expand Up @@ -54,7 +58,7 @@ const Follow: FC<FollowProps> = ({
const updateCache = () => {
cache.modify({
fields: { isFollowedByMe: () => true },
id: cache.identify(account.operations)
id: cache.identify(account.operations as LoggedInAccountOperations)
});
};

Expand Down
Loading

0 comments on commit c44d649

Please sign in to comment.