Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(feed): Parse MusicAudio and Video posts metadata on Map Feed #1400

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
10 changes: 4 additions & 6 deletions packages/components/socialFeed/Map/Map.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import {
import { zodTryParseJSON } from "@/utils/sanitize";
import {
CustomLatLngExpression,
parseSocialFeedMetadata,
PostCategory,
zodSocialFeedCommonMetadata,
ZodSocialFeedPostMetadata,
} from "@/utils/types/feed";

interface MarkerPopup {
Expand Down Expand Up @@ -134,11 +134,9 @@ export const Map: FC<MapProps> = ({
const markers: MarkerPopup[] = useMemo(() => {
if (!posts) return [];
const results: MarkerPopup[] = [];
posts.forEach((post, index) => {
const metadata = zodTryParseJSON(
ZodSocialFeedPostMetadata,
post.metadata,
);
posts.forEach((post) => {
const metadata = parseSocialFeedMetadata(post.category, post.metadata);

if (!metadata?.location) return;
results.push({
position: metadata.location,
Expand Down
36 changes: 36 additions & 0 deletions packages/utils/types/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from "zod";
import { LocalFileData, RemoteFileData, ZodRemoteFileData } from "./files";
import { Post } from "../../api/feed/v1/feed";
import { PostResult } from "../../contracts-clients/teritori-social-feed/TeritoriSocialFeed.types";
import { zodTryParseJSON } from "../sanitize";

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

Expand Down Expand Up @@ -135,3 +136,38 @@ export type ReplyToType = {
yOffsetValue?: number;
parentId?: string;
};

type GroupPostCategoryType = Omit<
PostCategory,
PostCategory.Video | PostCategory.Article | PostCategory.MusicAudio
>;

const postCategoriesGrouped: GroupPostCategoryType[] = [
PostCategory.Reaction,
PostCategory.Comment,
PostCategory.Normal,
PostCategory.Picture,
PostCategory.Question,
PostCategory.BriefForStableDiffusion,
PostCategory.Flagged,
PostCategory.VideoNote,
PostCategory.Audio,
];

const socialFeedSchemaMap: Record<PostCategory, z.ZodTypeAny> = {
[PostCategory.Video]: ZodSocialFeedVideoMetadata,
[PostCategory.Article]: ZodSocialFeedArticleMetadata,
[PostCategory.MusicAudio]: ZodSocialFeedTrackMetadata,
...Object.fromEntries(
postCategoriesGrouped.map((cat) => [cat, ZodSocialFeedPostMetadata]),
),
};

export const parseSocialFeedMetadata = (
category: PostCategory,
metadata: string,
) => {
const zodType = socialFeedSchemaMap[category];

return zodTryParseJSON(zodType, metadata);
};
Loading