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
25 changes: 25 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,27 @@ export type ReplyToType = {
yOffsetValue?: number;
parentId?: string;
};

export const parseSocialFeedMetadata = (
category: PostCategory,
metadata: string,
) => {
switch (category) {
case PostCategory.Video:
return (
zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) ||
zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata)
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return (
zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) ||
zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata)
);
return (
zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata)
);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Resolved it here: 0b9046c

case PostCategory.Article:
return (
zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) ||
zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata)
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return (
zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) ||
zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata)
);
return (
zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata)
);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Resolved it here: 0b9046c

case PostCategory.MusicAudio:
return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata);
case PostCategory.Normal:
return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata);
sujal-into marked this conversation as resolved.
Show resolved Hide resolved
default:
return zodTryParseJSON(zodSocialFeedCommonMetadata, metadata);
}
};
Loading