Skip to content

feat: show toast when post is shared by user#4251

Merged
AmarTrebinjac merged 22 commits intomainfrom
MI-812
May 19, 2025
Merged

feat: show toast when post is shared by user#4251
AmarTrebinjac merged 22 commits intomainfrom
MI-812

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

@vercel
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 May 19, 2025 7:23am
1 Skipped Deployment
Name Status Preview Updated (UTC)
storybook ⬜️ Ignored (Inspect) May 19, 2025 7:23am

@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 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 Author

Choose a reason for hiding this comment

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

Its not the issue, though. Its something else clearing it, and I haven't really figured out what 🤔
Removing the timeout works fine while the visiting user is logged in, but when the user is not, and the authbanner and all the other stuff pops in, it gets cleared early, even if I completely remove the eventlistener that is supposed to clear it early.

Here it is without timeout:

Screen.Recording.2025-05-08.at.21.59.15.mov

And here it is with 100ms timeout:

Screen.Recording.2025-05-08.at.21.58.22.mov

Not entirely sure what is causing this, but adding the small timeout and cleaning it up seems to solve the problem.

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?

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.

Other then follow button it looks good.

AmarTrebinjac and others added 2 commits May 9, 2025 10:30
Co-authored-by: Ante Barić <ante@kickass.website>
interface UseToastNotification {
displayToast: (message: string, params?: NotifyOptionalProps) => void;
displayToast: (
message: string | ReactNode,
Copy link
Contributor

Choose a reason for hiding this comment

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

ReactNode can be a string.

Suggested change
message: string | ReactNode,
message: ReactNode,


export interface ToastNotification {
message: string;
message: string | ReactNode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
message: string | ReactNode;
message: ReactNode;


const displayToast = (
message: string,
message: string | ReactNode,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
message: string | ReactNode,
message: ReactNode,

@AmarTrebinjac AmarTrebinjac merged commit 683f15c into main May 19, 2025
10 checks passed
@AmarTrebinjac AmarTrebinjac deleted the MI-812 branch May 19, 2025 07:29
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.

5 participants

Comments