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

feat: squad other section #2279

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft

Conversation

rebelchris
Copy link
Contributor

Changes

NOTE:

WIP: lots of TODO's and TS errors, but love to hear your overall thoughts.

Idea:

  • lean feed is less dependant on props and can work independant
  • lean actions should eventually be used by everything so there is one sole hook for actions per post (it needs a good cleanup/split maybe even)
  • modals should work via lazyModal and able to sit on top (still todo)

Events

Did you introduce any new tracking events?
Don't forget to update the Analytics Taxonomy sheet

Log the new/changed events below:

Type event_name value
Change/New event name extra: { ... }

Please make sure existing components are not breaking/affected by this PR

Manual Testing

On those affected packages:

  • Have you done sanity checks in the webapp?
  • Have you done sanity checks in the extension?
  • Does this not break anything in companion?

Did you test the modified components media queries?

  • MobileL (420px)
  • Tablet (656px)
  • Laptop (1020px)

Did you test on actual mobile devices?

  • iOS (Chrome and Safari)
  • Android

WT-{number} #done

: post,
);

const updateMap = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The final idea is to have one cache for post states, regardless of who needs it.
As the "intermediate" solution I thought we could have this mapping per query to say what transformer to run on the provided cache. (one issue still is how to update multiple places)

Copy link
Member

Choose a reason for hiding this comment

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

I suggest looking for normalized cache solutions or ignoring it, and in any way I wouldn't recommend doing it in the same PR. Developing one ourselves is too much effort and bug-prone

</p>
</div>
<div className={classNames(className, 'flex flex-col gap-6')}>
<ActiveFeedContextProvider items={similarPosts} queryKey={queryKey}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Items here can actually be removed, but had to leave it for legacy stuff for now.

() => ({
items,
queryKey,
onClick: onClick || onClickDefault,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We either can overwrite or keep the default click action.

const { feedRef } = useActiveFeedContext();

return (
<div className="grid grid-cols-2 gap-4" ref={feedRef}>
Copy link
Member

Choose a reason for hiding this comment

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

If this is to be a generic component, I suggest accepting classes from the outside and set it with default value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point indeed, most likely will take default "feed settings" and can get overwritten from outside.

Copy link
Contributor

@capJavert capJavert left a comment

Choose a reason for hiding this comment

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

Great work on the POC, appreciate the effort 🚀

Excited to plan and move it forward.

Comment on lines 11 to 13
{items.map((item, i) => {
return <LeanFeedItemComponent key={i} item={item} />;
})}
Copy link
Contributor

Choose a reason for hiding this comment

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

It could accept children as a function. So we can call:

Render cards:

<LeanFeed>
    {({ items }) => {
        return items.map((item, i) => {
            return <LeanFeedItemComponent key={i} item={item} />;
        }) 
    }}
</LeanFeed>

Add ad to the first place:

<LeanFeed>
    {({ items }) => {
        return items.map((item, i) => {
            if (i === 0) {
                return (
                    <>
                        <Ad />
                        <LeanFeedItemComponent key={i} item={item} />;
                    </>
                )
            }
    
            return <LeanFeedItemComponent key={i} item={item} />;
        }) 
    }}
</LeanFeed>

Of course internal render prop function is in fact just a component:

const FeedWithAds =  {({ items }) => {
    return items.map((item, i) => {
        return <LeanFeedItemComponent key={i} item={item} />;
    }) 
}}

<LeanFeed>
    {FeedWithAds}
</LeanFeed>

I think conceptually it would allow us to split view and business logic.

update: (oldPost: Post) => Partial<Post>,
): ((args: { id: string }) => Promise<() => void>) =>
async ({ id }) => {
await queryClient.cancelQueries(queryKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why cancel queries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Won't be needed, was more a copy-paste from the existing function :)

Comment on lines 54 to 71
const {
onPromotePost,
onBanPost,
canDeletePost,
onDeletePost,
canPinPost,
onPinPost,
onBlockSource,
onBlockTag,
onClick: onClickDefault,
onBookmark,
onUpvote,
onDownvote,
onHidePost,
} = useLeanPostActions({
queryKey,
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this top level, it should be called just in nested components?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can actually move into the nested components indeed.
The only exposure here I think was in case you can't to overwrite handlers?

Not sure if it's needed for that.

Comment on lines 86 to 89
export default function useLeanPostActions({
queryKey,
transformKey = 'further-reading',
}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea but I think component would need to be:

  • split up into smaller parts/hooks
  • based on your comment here it should support upvoting from single post as well
  • we should also see if it can utilize mutation subscriptions to sync state between different caches (as current hooks do)
  • should it solve props drilling in cards? feels like it should
  • don't get me wrong it looks great just with current functionality I think it's lacking any benefits vs current set of hooks 🙏 🚀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah 100% inline with the idea, Indeed the mutation subscription could potentially just check all caches for that postId and do something with it :)

And fully agree it should be split up again in singular logic, this was easier from a start point only.

Comment on lines 92 to 108
[
items,
onClick,
onBookmark,
onUpvote,
onDownvote,
onHidePost,
onPromotePost,
onBanPost,
canDeletePost,
onDeletePost,
canPinPost,
onPinPost,
onBlockSource,
onBlockTag,
queryKey,
],
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to be careful, this currently is going to make feed rendering as slow as it is now or worse.

Basically it should function the same as LeanOptionsButton where hooks down the render tree call useLeanPostActions and context only provides bare minimum like items and queryKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would we go about overwrites for onClick for instance in that case?
These overwrites per feed are pretty much the only scenario for it now.

Would love to hear your thoughts on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

You do the custom logic in that specialized component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But let's say it's canPinPost the page itself defines this.
The specialized component would have no way of knowing about it, unless it's contexted/prop drilled correct? (as it's implementation sits quite deep)

Copy link
Contributor

Choose a reason for hiding this comment

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

canPinPost would be something that is in the context then yes and component can decide what to do with it.

};

export default function useLeanPostActions({
queryKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, if we give single post query key it should invalidate single post cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep!

Copy link

vercel bot commented Nov 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
daily-webapp ❌ Failed (Inspect) Mar 21, 2024 1:44pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
storybook ⬜️ Ignored (Inspect) Visit Preview Mar 21, 2024 1:44pm

…-other-section

# Conflicts:
#	packages/shared/src/components/Feed.tsx
#	packages/shared/src/components/MainLayout.tsx
#	packages/shared/src/components/cards/ActionButtons.tsx
#	packages/shared/src/components/modals/common.tsx
#	packages/shared/src/components/post/PostActions.tsx
#	packages/shared/src/components/post/SquadPostContent.tsx
#	packages/shared/src/components/post/SquadPostWidgets.tsx
#	packages/shared/src/hooks/useOnPostClick.ts
#	packages/shared/src/hooks/usePostFeedback.ts
…-other-section

# Conflicts:
#	packages/shared/src/components/Feed.tsx
#	packages/shared/src/components/PostOptionsMenu.tsx
#	packages/shared/src/components/cards/ActionButtons.tsx
#	packages/shared/src/components/cards/Card.tsx
#	packages/shared/src/components/post/SquadPostWidgets.tsx
#	packages/shared/src/contexts/ActiveFeedContext.tsx
…-other-section

# Conflicts:
#	packages/shared/src/components/Feed.tsx
#	packages/shared/src/components/MainFeedLayout.tsx
#	packages/shared/src/components/MainLayout.tsx
#	packages/shared/src/components/post/SquadPostContent.tsx
#	packages/shared/src/components/utilities/common.tsx
#	packages/shared/src/contexts/ActiveFeedContext.tsx
#	packages/shared/src/hooks/useFeed.ts
#	packages/shared/src/hooks/useFeedLayout.ts
…-other-section

# Conflicts:
#	packages/shared/src/components/Feed.tsx
#	packages/shared/src/components/MainFeedLayout.tsx
#	packages/shared/src/components/feeds/FeedContainer.tsx
#	packages/shared/src/hooks/useFeedLayout.ts
#	packages/webapp/pages/onboarding.tsx
…-other-section

# Conflicts:
#	packages/shared/src/components/Feed.tsx
#	packages/shared/src/components/MainFeedLayout.tsx
#	packages/shared/src/components/PostOptionsMenu.tsx
#	packages/shared/src/components/feeds/FeedContainer.tsx
#	packages/shared/src/components/modals/common.tsx
#	packages/shared/src/hooks/useFeedLayout.ts
#	packages/shared/src/hooks/useOnPostClick.ts
#	packages/webapp/components/layouts/MainFeedPage.tsx
#	packages/webapp/pages/onboarding.tsx
…-other-section

# Conflicts:
#	packages/shared/src/components/Feed.tsx
#	packages/shared/src/components/buttons/Button.tsx
#	packages/shared/src/components/cards/Card.tsx
#	packages/shared/src/components/feeds/FeedContainer.tsx
#	packages/shared/src/components/post/SquadPostContent.tsx
#	packages/shared/src/components/post/SquadPostWidgets.tsx
#	packages/shared/src/components/squads/SquadFeedHeading.tsx
#	packages/shared/src/components/utilities/common.tsx
#	packages/shared/src/hooks/useFeed.ts
#	packages/shared/src/hooks/useFeedLayout.ts
#	packages/shared/src/hooks/useOnPostClick.ts
#	packages/webapp/components/layouts/MainFeedPage.tsx
#	packages/webapp/pages/onboarding.tsx
#	packages/webapp/pages/sources/[source].tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants