Skip to content

Commit 3a16113

Browse files
committed
fix: added a function to parse different social feed categories metadata
1 parent f2115fb commit 3a16113

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

packages/components/socialFeed/Map/Map.web.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import {
3434
import { zodTryParseJSON } from "@/utils/sanitize";
3535
import {
3636
CustomLatLngExpression,
37+
parseSocialFeedMetadata,
3738
PostCategory,
3839
zodSocialFeedCommonMetadata,
39-
ZodSocialFeedPostMetadata,
4040
} from "@/utils/types/feed";
4141

4242
interface MarkerPopup {
@@ -135,12 +135,8 @@ export const Map: FC<MapProps> = ({
135135
if (!posts) return [];
136136
const results: MarkerPopup[] = [];
137137
posts.forEach((post) => {
138-
const metadata = zodTryParseJSON(
139-
ZodSocialFeedPostMetadata.partial().merge(
140-
ZodSocialFeedPostMetadata.pick({ title: true }),
141-
),
142-
post.metadata,
143-
);
138+
const metadata = parseSocialFeedMetadata(post.category, post.metadata);
139+
144140
if (!metadata?.location) return;
145141
results.push({
146142
position: metadata.location,

packages/utils/types/feed.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { z } from "zod";
33
import { LocalFileData, RemoteFileData, ZodRemoteFileData } from "./files";
44
import { Post } from "../../api/feed/v1/feed";
55
import { PostResult } from "../../contracts-clients/teritori-social-feed/TeritoriSocialFeed.types";
6+
import { zodTryParseJSON } from "../sanitize";
67

78
export type OnPressReplyType = (replyTo: ReplyToType) => void;
89

@@ -135,3 +136,38 @@ export type ReplyToType = {
135136
yOffsetValue?: number;
136137
parentId?: string;
137138
};
139+
140+
type GroupPostCategoryType = Omit<
141+
PostCategory,
142+
PostCategory.Video | PostCategory.Article | PostCategory.MusicAudio
143+
>;
144+
145+
const postCategoriesGrouped: GroupPostCategoryType[] = [
146+
PostCategory.Reaction,
147+
PostCategory.Comment,
148+
PostCategory.Normal,
149+
PostCategory.Picture,
150+
PostCategory.Question,
151+
PostCategory.BriefForStableDiffusion,
152+
PostCategory.Flagged,
153+
PostCategory.VideoNote,
154+
PostCategory.Audio,
155+
];
156+
157+
const socialFeedSchemaMap: Record<PostCategory, z.ZodTypeAny> = {
158+
[PostCategory.Video]: ZodSocialFeedVideoMetadata,
159+
[PostCategory.Article]: ZodSocialFeedArticleMetadata,
160+
[PostCategory.MusicAudio]: ZodSocialFeedTrackMetadata,
161+
...Object.fromEntries(
162+
postCategoriesGrouped.map((cat) => [cat, ZodSocialFeedPostMetadata]),
163+
),
164+
};
165+
166+
export const parseSocialFeedMetadata = (
167+
category: PostCategory,
168+
metadata: string,
169+
) => {
170+
const zodType = socialFeedSchemaMap[category];
171+
172+
return zodTryParseJSON(zodType, metadata);
173+
};

0 commit comments

Comments
 (0)