fix(feed): Parse MusicAudio and Video posts metadata on Map Feed - #1400
sujal-into wants to merge 8 commits into
Conversation
✅ Deploy Preview for testitori ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for teritori-dapp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
| const metadata = zodTryParseJSON( | ||
| ZodSocialFeedPostMetadata, | ||
| ZodSocialFeedPostMetadata.partial().merge( | ||
| ZodSocialFeedPostMetadata.pick({ title: true }), |
There was a problem hiding this comment.
You don't need to modify the Zod type to try parse.
Yes, ZodSocialFeedPostMetadata shape can be wrong, but we have made other shapes for other posts categories. So we need to handle them.
Reformulation: The issue is due to the fact we have 4 differents types for the fetched posts.
Here we only try to parse ZodSocialFeedPostMetadata. So, the tracks and videos posts validation fails.
The result here has no success: https://github.com/TERITORI/teritori-dapp/blob/bugfix/video-audio-map/packages/utils/sanitize.ts#L22
If you console.log the result, you will see what's wrong to validate ZodSocialFeedPostMetadata
To avoid that, because the map gathers all posts categories, we must handle these Zod types. Here is my suggestion:
const videoPostMetadata = zodTryParseJSON(
ZodSocialFeedVideoMetadata,
post.metadata,
);
const trackMetadata = zodTryParseJSON(
ZodSocialFeedTrackMetadata,
post.metadata,
);
const articleMetadata = zodTryParseJSON(
ZodSocialFeedArticleMetadata,
post.metadata,
);
const postMetadata = zodTryParseJSON(
ZodSocialFeedPostMetadata,
post.metadata,
);
const metadataToUse = videoPostMetadata || trackMetadata || articleMetadata || postMetadata;
We need a refacto about it. Either unify all types in one, either add an utilitary function to handle (try parse) these differents zod types
There was a problem hiding this comment.
actually no there is the zodSocialFeedCommonMetadata schema when you need to only parse the title
There was a problem hiding this comment.
I have made a fix for this discussion in this commit: 3a16113
There was a problem hiding this comment.
actually no there is the
zodSocialFeedCommonMetadataschema when you need to only parse the title
In this case, there are other things that i need to parse also based on the category type, so I have created a util function to handle those cases.
There was a problem hiding this comment.
you can switch on the post type to do the proper parsing in each case, the whole point of using zod is to have type safety, using a z.ZodTypeAny entirely defeat this purpose
There was a problem hiding this comment.
I have used switch and removed the ZodTypeAny : ece2bac
n0izn0iz
left a comment
There was a problem hiding this comment.
no z.ZodTypeAny please
| switch (category) { | ||
| case PostCategory.Video: | ||
| return zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata); | ||
| case PostCategory.Article: | ||
| return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); | ||
| case PostCategory.MusicAudio: | ||
| return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata); | ||
| default: | ||
| return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); | ||
| } |
There was a problem hiding this comment.
| switch (category) { | |
| case PostCategory.Video: | |
| return zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata); | |
| case PostCategory.Article: | |
| return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); | |
| case PostCategory.MusicAudio: | |
| return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata); | |
| default: | |
| return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); | |
| } | |
| switch (category) { | |
| case PostCategory.Video: | |
| return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata); | |
| case PostCategory.Article: | |
| return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata); | |
| case PostCategory.MusicAudio: | |
| return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata); | |
| default: | |
| return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); | |
| } |
- Use ZodSocialFeedArticleMetadata for Articles
- Hanlde the "old" posts. Example: https://github.com/TERITORI/teritori-dapp/blob/bugfix/video-audio-map/packages/components/socialFeed/Map/MapPosts/ArticleMapPost.tsx#L24-L26
We'll make another PR to replace all zodTryParseJSON usages by parseSocialFeedMetadata (About posts)
There was a problem hiding this comment.
Hanlde the "old" posts
actually we will reset the feed after redesigning the contracts so I don't think it's important to support old stuff right now
even "We'll make another PR to replace all zodTryParseJSON usages by parseSocialFeedMetadata (About posts)" is not necessary since we'll have well defined types from contracts
There was a problem hiding this comment.
@n0izn0iz Yes, some issues are "stand by" for now
n0izn0iz
left a comment
There was a problem hiding this comment.
if you need other cases, add them, there should be one zod schema for one post category and the fallback is common metadata
Co-authored-by: n0izn0iz <n0izn0iz@users.noreply.github.com>
Co-authored-by: n0izn0iz <n0izn0iz@users.noreply.github.com>
| return ( | ||
| zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || | ||
| zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata) | ||
| ); |
There was a problem hiding this comment.
| return ( | |
| zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || | |
| zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata) | |
| ); | |
| return ( | |
| zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata) | |
| ); |
| return ( | ||
| zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || | ||
| zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata) | ||
| ); |
There was a problem hiding this comment.
| return ( | |
| zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || | |
| zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata) | |
| ); | |
| return ( | |
| zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata) | |
| ); |
✅ Deploy Preview for gno-dapp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
So, we pause that, we need refacto |
fix: #1370