-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually no there is the zodSocialFeedCommonMetadata
schema when you need to only parse the title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made a fix for this discussion in this commit: 3a16113
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually no there is the
zodSocialFeedCommonMetadata
schema 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have used switch and removed the ZodTypeAny : ece2bac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no z.ZodTypeAny
please
packages/utils/types/feed.ts
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made changes here: 8a0ebc6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@n0izn0iz Yes, some issues are "stand by" for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Co-authored-by: n0izn0iz <[email protected]>
packages/utils/types/feed.ts
Outdated
return ( | ||
zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || | ||
zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ( | |
zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || | |
zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata) | |
); | |
return ( | |
zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata) | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved it here: 0b9046c
packages/utils/types/feed.ts
Outdated
return ( | ||
zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || | ||
zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ( | |
zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || | |
zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata) | |
); | |
return ( | |
zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata) | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved it here: 0b9046c
fix: #1370