From 13105ee4177edb75d31b43d2bd1161516dcc8b8a Mon Sep 17 00:00:00 2001 From: Innei Date: Thu, 19 Sep 2024 23:25:03 +0800 Subject: [PATCH] feat(ux): rotating icon when reset rotate back Signed-off-by: Innei --- apps/renderer/src/components/ui/loading.tsx | 28 ++++++++++++++++++- .../entry-column/layouts/EntryListHeader.tsx | 12 ++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/apps/renderer/src/components/ui/loading.tsx b/apps/renderer/src/components/ui/loading.tsx index 64902530b..e6523814e 100644 --- a/apps/renderer/src/components/ui/loading.tsx +++ b/apps/renderer/src/components/ui/loading.tsx @@ -1,4 +1,5 @@ -import React, { cloneElement } from "react" +import { m, useAnimation } from "framer-motion" +import React, { cloneElement, useEffect } from "react" import { cn } from "~/lib/utils" @@ -112,3 +113,28 @@ export const LoadingWithIcon: Component< ) } } + +export const RotatingRefreshIcon: React.FC<{ + isRefreshing: boolean + className?: string +}> = ({ isRefreshing, className }) => { + const controls = useAnimation() + + useEffect(() => { + if (isRefreshing) { + controls.set({ rotate: 0 }) + controls.start({ + rotate: 360, + transition: { duration: 1, repeat: Infinity, ease: "linear" }, + }) + } else { + controls.stop() + controls.start({ + rotate: 360, + transition: { ease: "linear", type: "spring" }, + }) + } + }, [isRefreshing, controls]) + + return +} diff --git a/apps/renderer/src/modules/entry-column/layouts/EntryListHeader.tsx b/apps/renderer/src/modules/entry-column/layouts/EntryListHeader.tsx index 04161397a..780fcd562 100644 --- a/apps/renderer/src/modules/entry-column/layouts/EntryListHeader.tsx +++ b/apps/renderer/src/modules/entry-column/layouts/EntryListHeader.tsx @@ -8,6 +8,7 @@ import { useWhoami } from "~/atoms/user" import { ImpressionView } from "~/components/common/ImpressionTracker" import { ActionButton } from "~/components/ui/button" import { DividerVertical } from "~/components/ui/divider" +import { RotatingRefreshIcon } from "~/components/ui/loading" import { EllipsisHorizontalTextWithTooltip } from "~/components/ui/typography" import { FEED_COLLECTION_LIST, ROUTE_ENTRY_PENDING, views } from "~/constants" import { shortcuts } from "~/constants/shortcuts" @@ -109,7 +110,7 @@ export const EntryListHeader: FC<{ refreshFeed() }} > - + ) : ( - )