From c1c7372d0daf5dfd79e80c49403c390fd9bdd494 Mon Sep 17 00:00:00 2001 From: Innei Date: Sat, 8 Jul 2023 15:47:04 +0800 Subject: [PATCH] feat: motion Signed-off-by: Innei --- src/app/thinking/page.tsx | 36 +++++++++++++++++++++++--- src/components/layout/header/config.ts | 2 +- src/hooks/common/use-previous.ts | 9 +++++++ src/lib/url-builder.ts | 5 ++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/hooks/common/use-previous.ts diff --git a/src/app/thinking/page.tsx b/src/app/thinking/page.tsx index 590c2829fc..b958ee69f9 100644 --- a/src/app/thinking/page.tsx +++ b/src/app/thinking/page.tsx @@ -1,8 +1,9 @@ 'use client' import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query' -import { useMemo, useState } from 'react' +import { useEffect, useMemo, useState } from 'react' import clsx from 'clsx' +import { stagger, useAnimate } from 'framer-motion' import { produce } from 'immer' import type { RecentlyModel } from '@mx-space/api-client' import type { InfiniteData } from '@tanstack/react-query' @@ -25,6 +26,7 @@ import { CommentBoxRoot } from '~/components/widgets/comment/CommentBox' import { Comments } from '~/components/widgets/comment/Comments' import { PeekLink } from '~/components/widgets/peek/PeekLink' import { LoadMoreIndicator } from '~/components/widgets/shared/LoadMoreIndicator' +import { usePrevious } from '~/hooks/common/use-previous' import { sample } from '~/lib/_' import { preventDefault } from '~/lib/dom' import { apiClient } from '~/lib/request' @@ -156,16 +158,44 @@ const List = () => { } const { present } = useModalStack() + const [scope, animate] = useAnimate() + + const getPrevData = usePrevious(data) + useEffect(() => { + if (!data) return + const pages = getPrevData()?.pages + const count = pages?.reduce((acc, cur) => { + return acc + cur.length + }, 0) + + console.log(count) + + animate( + 'li', + { + opacity: 1, + y: 0, + }, + { + duration: 0.2, + delay: stagger(0.1, { + startDelay: 0.15, + from: count ? count - FETCH_SIZE : 0, + }), + }, + ) + }, [data]) + if (isLoading) return ( -
    +
      {data?.pages.map((page) => { return page.map((item) => { return (
    • (value: T): (() => T | undefined) => { + const ref = useRef() + useEffect(() => { + ref.current = value + }, [value]) + return () => ref.current +} diff --git a/src/lib/url-builder.ts b/src/lib/url-builder.ts index 1570580dda..f43b2f0bd3 100644 --- a/src/lib/url-builder.ts +++ b/src/lib/url-builder.ts @@ -33,6 +33,11 @@ function isNoteModel(model: any): model is NoteModel { function buildUrl(model: PostModel | NoteModel | PageModel) { if (isPostModel(model)) { + // TODO + if (!model.category) { + console.error('PostModel.category is missing!!!!!') + return '#' + } return `/posts/${ (model.category as CategoryModel).slug }/${encodeURIComponent(model.slug)}`