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: show toast when post is shared by user #4251

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

AmarTrebinjac
Copy link
Contributor

@AmarTrebinjac AmarTrebinjac commented Mar 2, 2025

Changes

TASK
DESIGN
SPEC
Screenshot 2025-03-03 at 00 28 36

Not going to lie, I struggled a little bit with this one. The toast kept getting "wiped" due to state/cache updates and other weird stuff. Solve one scenario, two new ones pop up. 😭

I ended up wrapping it in a timeout to make sure the page has loaded most of its content before showing it. If any of you got any better suggestion as to how to make sure the toast does not get insta-wiped, feel free to make them.

Example:
Screenshot 2025-03-03 at 00 22 01

Note that there's a bit more padding left to the avatar than there is on the design. It's because we have padding left + margin in our toast. I thought instead of creating unnecessary props or overriding, we just leave it be as is, and let design know. Let me know if this is disagreeable.

Events

Did you introduce any new tracking events?

Experiment

Did you introduce any new experiments?

Manual Testing

Caution

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

Preview domain

https://mi-812.preview.app.daily.dev

Jira ticket

MI-812

Copy link

vercel bot commented Mar 2, 2025

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

Name Status Preview Updated (UTC)
daily-webapp ✅ Ready (Inspect) Visit Preview Mar 13, 2025 11:32am
1 Skipped Deployment
Name Status Preview Updated (UTC)
storybook ⬜️ Ignored (Inspect) Mar 13, 2025 11:32am

@AmarTrebinjac AmarTrebinjac marked this pull request as ready for review March 4, 2025 08:25
@AmarTrebinjac AmarTrebinjac requested a review from a team as a code owner March 4, 2025 08:25
Comment on lines 24 to 30
const { data: contentPreference, isPending } =
useContentPreferenceStatusQuery({
id: userId,
entity: ContentPreferenceType.User,
});
const { data: user } = useUserShortByIdQuery({ id: userId });
const { follow } = useContentPreference({ showToastOnSuccess: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we currently blocking those queries if the post author is the current logged in user? We should avoid network calls in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of these handle it already. But it doesn't matter that much because its not visual and cases where users visit their own link is already low.

Comment on lines 43 to 45
setTimeout(() => {
hasShownToast.current = true;
displayToast(
Copy link
Contributor

@ilasw ilasw Mar 4, 2025

Choose a reason for hiding this comment

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

I’m not really a fan of using setTimeout inside useEffect, but I think we should handle the case where a user lands on the page and then quickly navigates back to the home page.

I suggest adding a ref to store the timerId, then clearing the timer on unmount. We should also clear it if the userId changes to prevent issues when navigating between shared posts. Wdyt?

Copy link
Contributor

@capJavert capJavert Mar 4, 2025

Choose a reason for hiding this comment

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

+1 we have to clear timeout, it introduces memory leaks

Copy link
Contributor

Choose a reason for hiding this comment

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

But toast already handles timeout internally why do you need another manual timeout?

Copy link
Contributor Author

@AmarTrebinjac AmarTrebinjac Mar 13, 2025

Choose a reason for hiding this comment

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

@rebelchris Because what I mentioned in the OP, for some reason if we pop the toast instantly it gets cleared immediately. I am assuming there's some state updates / mounting stuff going on. It's a bit of a hacky fix, but at the same time by delaying it just a little, it also ensures that the toast is visible when the user is looking at the page and it isnt shifting around.

Copy link
Contributor

Choose a reason for hiding this comment

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

But you can pass a prop to keep it between page shifts, it's an option already

Copy link
Contributor

@rebelchris rebelchris left a comment

Choose a reason for hiding this comment

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

Minor requests

Comment on lines 43 to 45
setTimeout(() => {
hasShownToast.current = true;
displayToast(
Copy link
Contributor

Choose a reason for hiding this comment

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

But toast already handles timeout internally why do you need another manual timeout?

entityName: `@${user.username}`,
});
}}
className="bg-background-default text-text-primary"
Copy link
Contributor

Choose a reason for hiding this comment

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

This can't be right, is it not a guideline button?

>
<ProfilePicture user={user} size={ProfileImageSize.Medium} />
<span>
<Typography tag={TypographyTag.Span} bold>
Copy link
Contributor

Choose a reason for hiding this comment

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

You are missing the types here, it can break on some implementation.
(Note to self t make it mandatory)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactor to as const as well ? 🤪

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