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

TBD Proposal cards animation #4996

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

Conversation

mstrasinskis
Copy link
Contributor

@mstrasinskis mstrasinskis commented Jun 4, 2024

Motivation

This PR adds animation to the /proposals page cards, making it clearer for users to understand that the universe were switched. The animation will also keep users engaged and improve the overall user experience.

Changes

  • Added constants for card animation.
  • Added utility function isHtmlElementInViewport.
  • Provided card index to the ProposalCard component, allowing each card to determine its animation start time (with a default value, since it's not a critical feature).
  • Implemented a sequential fly animation in the ProposalCard component:
    • |global modificator was applied to make the animation work between pages. Only in transition was used. No navigation issues detected.
    • Only visible cards will be animated (due to animation duration, checking card visibility only at creation suffices).
    • Only the first 18 cards (maximum visible count on large screens) are animated with the sequential effect.
    • Other cards appear using a simultaneous animation to maintain a smooth experience for lazy-loaded proposals.
  • Added logic to UniverseWithActionableProposals to prevent animation of the first headline and initiate animation of the next headline after the standard animation duration.
  • Added fade animation for the proposals page loaders and banners.

Tests

Todos

  • Add entry to changelog (if necessary).

@mstrasinskis mstrasinskis marked this pull request as ready for review June 4, 2024 13:09
@mstrasinskis mstrasinskis requested a review from a team as a code owner June 4, 2024 13:09
{#each $openSnsProposalsStore as proposalInfo (proposalInfo.id)}
<NnsProposalCard {proposalInfo} />
{#each $openSnsProposalsStore as proposalInfo, index (proposalInfo.id)}
<NnsProposalCard {proposalInfo} {index} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want the proposal on the SNS page to slide in while the other 2 cards don't?


export let universe: Universe;
export let proposals: ProposalData[];
export let cardIndex = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about cardIndexOffset?


export let universe: Universe;
export let delay = 0;
export let noAnimation = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this prop? Just leaving the delay at 0 has the same effect, no?


export let universe: Universe;
export let delay = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use a clearer name. Something like titleFadeInDelay?

import { isNode } from "$lib/utils/dev.utils";
import { isHtmlElementInViewport } from "$lib/utils/utils";

export let index = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use a more specific name? Something like animationIndex?
Same for similar props in other card components.

{#each actionableUniverses as { universe, proposals } (universe.canisterId)}
<ActionableSnsProposals {universe} {proposals} />
<ActionableSnsProposals {universe} {proposals} {cardIndex} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't cardIndex be incremented per each universe by the number of cards before it?


let inViewport: boolean = false;
$: inViewport =
isNode() || isNullish(element) ? true : isHtmlElementInViewport(element);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why exactly do we call isNode here from dev.utils?


let inViewport: boolean = false;
$: inViewport =
isNode() || isNullish(element) ? true : isHtmlElementInViewport(element);
Copy link
Contributor

Choose a reason for hiding this comment

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

If I read the logic correctly, we treat an element that is null is being in the viewport. Is that correct?

top >= 0 &&
left >= 0 &&
bottom <= window.innerHeight &&
right <= window.innerWidth
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only true if the element is entirely inside the viewport. If even the slightest bit is outside but the element is mostly visible, it will return false.
Shouldn't it be the opposite where we want to animate a card also if it's partially visible?

Either way, we should clearly document this.

export const SVELTE_DEFAULT_ANIMATION_DURATION_IN_MILLISECOND = 400;
export const PROPOSAL_CARD_ANIMATION_DURATION_IN_MILLISECOND =
SVELTE_DEFAULT_ANIMATION_DURATION_IN_MILLISECOND;
// Maximum 10 card animations at a time
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this comment refer to?
It doesn't seem to have anything to do with the line above or below it.

And should it be 18 instead of 10? The PR description says 18. Or is that something else?

@mstrasinskis mstrasinskis marked this pull request as draft June 10, 2024 15:10
@mstrasinskis mstrasinskis changed the title Proposal cards animation TBD Proposal cards animation Jun 10, 2024
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.

2 participants