Skip to content

Commit

Permalink
πŸ” Rename publication to post for v3 preparation: v10 (#pre-lens-v3)
Browse files Browse the repository at this point in the history
Summary: Renamed `Publications` to `Posts` and updated search functionality.

Highlights:

β€’ Added `Posts.tsx` to handle search results, replacing `Publications`.
β€’ Integrated `useSearchPublicationsQuery` for fetching and displaying posts.
β€’ Updated `index.tsx` to use `Posts` component for publication searches.

Read more: https://pierre.co/hey/hey/pre-lens-v3
  • Loading branch information
Yoginth authored and Pierre committed Nov 14, 2024
1 parent ee82cb9 commit 19cd9c2
Show file tree
Hide file tree
Showing 39 changed files with 126 additions and 155 deletions.
6 changes: 3 additions & 3 deletions apps/api/src/routes/ai/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const post = [
.json({ result: JSON.parse(cachedData), success: true });
}

const publicationMetadata = await lensPg.query(
const postMetadata = await lensPg.query(
"SELECT content FROM publication.metadata WHERE publication_id = $1",
[id]
);
Expand All @@ -72,7 +72,7 @@ export const post = [
messages: [
{
role: "user",
content: TEMPLATE.replace("{text}", publicationMetadata[0].content)
content: TEMPLATE.replace("{text}", postMetadata[0].content)
}
],
tools: [
Expand All @@ -88,7 +88,7 @@ export const post = [
.parsed_arguments as responseSchema;

const finalResult = {
original: publicationMetadata[0].content,
original: postMetadata[0].content,
...translated
};

Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/badges/hasHeyNft.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HEY_MEMBERSHIP_NFT_PUBLICATION_ID } from "@hey/data/constants";
import { HEY_MEMBERSHIP_NFT_POST_ID } from "@hey/data/constants";
import lensPg from "@hey/db/lensPg";
import { getRedis, setRedis } from "@hey/db/redisClient";
import logger from "@hey/helpers/logger";
Expand Down Expand Up @@ -49,7 +49,7 @@ export const get = [
AND o.publication_id = $3
) AS exists;
`,
[id, formattedAddress, HEY_MEMBERSHIP_NFT_PUBLICATION_ID]
[id, formattedAddress, HEY_MEMBERSHIP_NFT_POST_ID]
);

const hasHeyNft = openActionModuleActed[0]?.exists;
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/lens/internal/stats/nft-revenue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HEY_MEMBERSHIP_NFT_PUBLICATION_ID } from "@hey/data/constants";
import { HEY_MEMBERSHIP_NFT_POST_ID } from "@hey/data/constants";
import lensPg from "@hey/db/lensPg";
import logger from "@hey/helpers/logger";
import type { Request, Response } from "express";
Expand All @@ -23,7 +23,7 @@ export const get = [
GROUP BY date
ORDER BY date;
`,
[HEY_MEMBERSHIP_NFT_PUBLICATION_ID]
[HEY_MEMBERSHIP_NFT_POST_ID]
);

const result = openActionModuleActed.map((row) => ({
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/routes/lens/internal/stats/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export const get = [
FROM pg_class
WHERE relname = 'usage' AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'relay');
SELECT reltuples::BIGINT AS publications_count
SELECT reltuples::BIGINT AS posts_count
FROM pg_class
WHERE relname = 'record' AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'publication');
SELECT reltuples::BIGINT AS profiles_count
FROM pg_class
WHERE relname = 'record' AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'profile');
SELECT reltuples::BIGINT AS bookmarked_publications_count
SELECT reltuples::BIGINT AS bookmarked_posts_count
FROM pg_class
WHERE relname = 'bookmarked_publication' AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'personalisation');
SELECT reltuples::BIGINT AS not_interested_publications_count
SELECT reltuples::BIGINT AS not_interested_posts_count
FROM pg_class
WHERE relname = 'not_interested_publication' AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'personalisation');
Expand Down
8 changes: 3 additions & 5 deletions apps/api/src/routes/lists/publications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const get = [
const offset =
(Number.parseInt(page as string) - 1) * Number.parseInt(size as string);

const publications = await lensPg.query(
const posts = await lensPg.query(
`
SELECT publication_id AS id
FROM publication_view
Expand All @@ -45,12 +45,10 @@ export const get = [
[size, offset]
);

logger.info(
`List publications fetched for ${id}, page ${page}, size ${size}`
);
logger.info(`List posts fetched for ${id}, page ${page}, size ${size}`);

return res.status(200).json({
result: publications.map((row) => row.id),
result: posts.map((row) => row.id),
size,
offset,
success: true
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/sitemap/posts.xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export const get = async (req: Request, res: Response) => {
totalPosts = Number(cachedData);
logger.info(`[Lens] Fetched totalPosts from Redis: ${totalPosts}`);
} else {
const publications = await lensPg.query(`
const posts = await lensPg.query(`
SELECT COUNT(*) AS count
FROM publication.record pr
WHERE pr.publication_type = 'POST' AND pr.is_hidden = false
`);

totalPosts = Number(publications[0]?.count) || 0;
totalPosts = Number(posts[0]?.count) || 0;
await setRedis(redisKey, totalPosts);
logger.info(`[Lens] Fetched totalPosts from DB: ${totalPosts}`);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/stats/post/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const post = [
id: row.publication,
views: Number(row.count)
}));
logger.info(`Fetched post views for ${ids.length} publications`);
logger.info(`Fetched post views for ${ids.length} posts`);

return res.status(200).json({ success: true, views: viewCounts });
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/tips/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const post = [
tipped: hasTippedMap.has(publicationId)
}));

logger.info(`Fetched tips for ${ids.length} publications`);
logger.info(`Fetched tips for ${ids.length} posts`);

return res.status(200).json({ result, success: true });
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/tests/lens/internal/stats/overview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("GET /lens/internal/stats/overview", () => {
expect(typeof data.result).toBe("object");
expect(data.result).toHaveProperty("authentications_count");
expect(data.result).toHaveProperty("relay_usage_count");
expect(data.result).toHaveProperty("publications_count");
expect(data.result).toHaveProperty("posts_count");
expect(data.result).toHaveProperty("profiles_count");
});

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Comment/CommentFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
LimitType,
usePublicationsQuery
} from "@hey/lens";
import { OptmisticPublicationType } from "@hey/types/enums";
import { OptmisticPostType } from "@hey/types/enums";
import { Card, EmptyState, ErrorMessage } from "@hey/ui";
import type { FC } from "react";
import { Virtuoso } from "react-virtuoso";
Expand Down Expand Up @@ -58,7 +58,7 @@ const CommentFeed: FC<CommentFeedProps> = ({ postId }) => {
const hasMore = pageInfo?.next;

const queuedComments = txnQueue.filter(
(o) => o.type === OptmisticPublicationType.Comment && o.commentOn === postId
(o) => o.type === OptmisticPostType.Comment && o.commentOn === postId
);
const queuedCount = queuedComments.length;
const hiddenCount = comments.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
LensTransactionStatusType,
useLensTransactionStatusQuery
} from "@hey/lens";
import { OptmisticPublicationType } from "@hey/types/enums";
import { OptmisticPostType } from "@hey/types/enums";
import type { OptimisticTransaction } from "@hey/types/misc";
import type { FC } from "react";
import { useTransactionStore } from "src/store/persisted/useTransactionStore";
Expand All @@ -22,7 +22,7 @@ const Transaction: FC<{ transaction: OptimisticTransaction }> = ({
) {
// Trigger Profile feed refetch
if (
transaction.type === OptmisticPublicationType.Post &&
transaction.type === OptmisticPostType.Post &&
lensTransactionStatus.txHash
) {
setIndexedPostHash(lensTransactionStatus.txHash);
Expand Down
12 changes: 6 additions & 6 deletions apps/web/src/components/Home/ForYou.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PostsShimmer from "@components/Shared/Shimmer/PostsShimmer";
import { LightBulbIcon } from "@heroicons/react/24/outline";
import type { AnyPublication, PublicationForYouRequest } from "@hey/lens";
import { LimitType, useForYouQuery } from "@hey/lens";
import { OptmisticPublicationType } from "@hey/types/enums";
import { OptmisticPostType } from "@hey/types/enums";
import { Card, EmptyState, ErrorMessage } from "@hey/ui";
import type { FC } from "react";
import { Virtuoso } from "react-virtuoso";
Expand Down Expand Up @@ -33,7 +33,7 @@ const ForYou: FC = () => {
variables: { request }
});

const publications = data?.forYou?.items;
const posts = data?.forYou?.items;
const pageInfo = data?.forYou?.pageInfo;
const hasMore = pageInfo?.next;

Expand All @@ -52,7 +52,7 @@ const ForYou: FC = () => {
return <PostsShimmer />;
}

if (publications?.length === 0) {
if (posts?.length === 0) {
return (
<EmptyState
icon={<LightBulbIcon className="size-8" />}
Expand All @@ -68,20 +68,20 @@ const ForYou: FC = () => {
return (
<>
{txnQueue.map((txn) =>
txn?.type === OptmisticPublicationType.Post ? (
txn?.type === OptmisticPostType.Post ? (
<QueuedPost key={txn.txId} txn={txn} />
) : null
)}
<Card>
<Virtuoso
className="virtual-divider-list-window"
computeItemKey={(index, item) => `${item.publication.id}-${index}`}
data={publications}
data={posts}
endReached={onEndReached}
itemContent={(index, item) => (
<SinglePost
isFirst={index === 0}
isLast={index === (publications?.length || 0) - 1}
isLast={index === (posts?.length || 0) - 1}
post={item.publication as AnyPublication}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import CollectAction from "@components/Post/OpenAction/CollectModule/CollectAction";
import Loader from "@components/Shared/Loader";
import { signatureFont } from "@helpers/fonts";
import {
APP_NAME,
HEY_MEMBERSHIP_NFT_PUBLICATION_ID
} from "@hey/data/constants";
import { APP_NAME, HEY_MEMBERSHIP_NFT_POST_ID } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import type { Post } from "@hey/lens";
import { usePublicationQuery } from "@hey/lens";
Expand All @@ -20,7 +17,7 @@ interface MintProps {
const Mint: FC<MintProps> = ({ onCollectSuccess }) => {
const { data, error, loading } = usePublicationQuery({
variables: {
request: { forId: HEY_MEMBERSHIP_NFT_PUBLICATION_ID }
request: { forId: HEY_MEMBERSHIP_NFT_POST_ID }
}
});

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Home/Timeline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UserGroupIcon } from "@heroicons/react/24/outline";
import { HEY_CURATED_ID } from "@hey/data/constants";
import type { AnyPublication, FeedItem, FeedRequest } from "@hey/lens";
import { FeedEventItemType, useFeedQuery } from "@hey/lens";
import { OptmisticPublicationType } from "@hey/types/enums";
import { OptmisticPostType } from "@hey/types/enums";
import { Card, EmptyState, ErrorMessage } from "@hey/ui";
import type { FC } from "react";
import { memo, useRef } from "react";
Expand Down Expand Up @@ -97,7 +97,7 @@ const Timeline: FC = () => {
return (
<>
{txnQueue.map((txn) =>
txn?.type !== OptmisticPublicationType.Comment ? (
txn?.type !== OptmisticPostType.Comment ? (
<QueuedPost key={txn.txId} txn={txn} />
) : null
)}
Expand Down
24 changes: 12 additions & 12 deletions apps/web/src/components/List/ListFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Virtuoso } from "react-virtuoso";
import { useImpressionsStore } from "src/store/non-persisted/useImpressionsStore";
import { useTipsStore } from "src/store/non-persisted/useTipsStore";

const GET_LIST_PUBLICATIONS_QUERY_KEY = "getListPublications";
const GET_LIST_POSTS_QUERY_KEY = "getListPosts";
let virtuosoState: any = { ranges: [], screenTop: 0 };

interface ListFeedProps {
Expand All @@ -34,7 +34,7 @@ const ListFeed: FC<ListFeedProps> = ({ list, showHeader = false }) => {
virtuosoState = { ranges: [], screenTop: 0 };
}, [list.id]);

const getListPublications = async (id: string): Promise<string[]> => {
const getListPosts = async (id: string): Promise<string[]> => {
try {
const { data } = await axios.get(`${HEY_API_URL}/lists/publications`, {
params: { id }
Expand All @@ -47,17 +47,17 @@ const ListFeed: FC<ListFeedProps> = ({ list, showHeader = false }) => {
};

const {
data: publicationIds,
isLoading: loadingPublicationIds,
error: errorPublicationIds
data: postIds,
isLoading: loadingPostIds,
error: errorPostIds
} = useQuery({
queryFn: () => getListPublications(list.id),
queryKey: [GET_LIST_PUBLICATIONS_QUERY_KEY, list.id]
queryFn: () => getListPosts(list.id),
queryKey: [GET_LIST_POSTS_QUERY_KEY, list.id]
});

const request: PublicationsRequest = {
limit: LimitType.TwentyFive,
where: { publicationIds }
where: { publicationIds: postIds }
};

const {
Expand All @@ -73,7 +73,7 @@ const ListFeed: FC<ListFeedProps> = ({ list, showHeader = false }) => {
await fetchAndStoreViews(ids);
await fetchAndStoreTips(ids);
},
skip: !publicationIds?.length,
skip: !postIds?.length,
variables: { request }
});

Expand All @@ -87,7 +87,7 @@ const ListFeed: FC<ListFeedProps> = ({ list, showHeader = false }) => {
}
};

if (loadingPublicationIds || publicationsLoading) {
if (loadingPostIds || publicationsLoading) {
return <PostsShimmer />;
}

Expand Down Expand Up @@ -120,12 +120,12 @@ const ListFeed: FC<ListFeedProps> = ({ list, showHeader = false }) => {
);
}

if (errorPublicationIds || publicationsError) {
if (errorPostIds || publicationsError) {
return (
<Card>
<Header />
<ErrorMessage
error={errorPublicationIds || publicationsError}
error={errorPostIds || publicationsError}
title="Failed to load list feed"
/>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface ActedNotificationProps {
}

const ActedNotification: FC<ActedNotificationProps> = ({ notification }) => {
const publication = notification?.publication;
const targetPost = isRepost(publication) ? publication.mirrorOn : publication;
const post = notification?.publication;
const targetPost = isRepost(post) ? post.mirrorOn : post;
const { metadata } = targetPost;
const filteredContent = getPostData(metadata)?.content || "";
const actions = notification?.actions;
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Post/Actions/Share/Mirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
useMirrorOnMomokaMutation,
useMirrorOnchainMutation
} from "@hey/lens";
import { OptmisticPublicationType } from "@hey/types/enums";
import { OptmisticPostType } from "@hey/types/enums";
import type { OptimisticTransaction } from "@hey/types/misc";
import cn from "@hey/ui/cn";
import { useCounter } from "@uidotdev/usehooks";
Expand Down Expand Up @@ -77,7 +77,7 @@ const Mirror: FC<MirrorProps> = ({ isLoading, post, setIsLoading }) => {
mirrorOn: post?.id,
txHash,
txId,
type: OptmisticPublicationType.Mirror
type: OptmisticPostType.Mirror
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
useBroadcastOnchainMutation,
useCreateActOnOpenActionTypedDataMutation
} from "@hey/lens";
import { OptmisticPublicationType } from "@hey/types/enums";
import { OptmisticPostType } from "@hey/types/enums";
import type { OptimisticTransaction } from "@hey/types/misc";
import { Button, WarningMessage } from "@hey/ui";
import cn from "@hey/ui/cn";
Expand Down Expand Up @@ -136,7 +136,7 @@ const CollectAction: FC<CollectActionProps> = ({
collectOn: post?.id,
txHash,
txId,
type: OptmisticPublicationType.Collect
type: OptmisticPostType.Collect
};
};

Expand Down
Loading

1 comment on commit 19cd9c2

@vercel
Copy link

@vercel vercel bot commented on 19cd9c2 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./

web-heyxyz.vercel.app
web-git-main-heyxyz.vercel.app
hey.xyz
heyxyz.vercel.app

Please sign in to comment.