Skip to content

Commit c1c7372

Browse files
committed
feat: motion
Signed-off-by: Innei <[email protected]>
1 parent 43d7e05 commit c1c7372

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

src/app/thinking/page.tsx

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use client'
22

33
import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query'
4-
import { useMemo, useState } from 'react'
4+
import { useEffect, useMemo, useState } from 'react'
55
import clsx from 'clsx'
6+
import { stagger, useAnimate } from 'framer-motion'
67
import { produce } from 'immer'
78
import type { RecentlyModel } from '@mx-space/api-client'
89
import type { InfiniteData } from '@tanstack/react-query'
@@ -25,6 +26,7 @@ import { CommentBoxRoot } from '~/components/widgets/comment/CommentBox'
2526
import { Comments } from '~/components/widgets/comment/Comments'
2627
import { PeekLink } from '~/components/widgets/peek/PeekLink'
2728
import { LoadMoreIndicator } from '~/components/widgets/shared/LoadMoreIndicator'
29+
import { usePrevious } from '~/hooks/common/use-previous'
2830
import { sample } from '~/lib/_'
2931
import { preventDefault } from '~/lib/dom'
3032
import { apiClient } from '~/lib/request'
@@ -156,16 +158,44 @@ const List = () => {
156158
}
157159
const { present } = useModalStack()
158160

161+
const [scope, animate] = useAnimate()
162+
163+
const getPrevData = usePrevious(data)
164+
useEffect(() => {
165+
if (!data) return
166+
const pages = getPrevData()?.pages
167+
const count = pages?.reduce((acc, cur) => {
168+
return acc + cur.length
169+
}, 0)
170+
171+
console.log(count)
172+
173+
animate(
174+
'li',
175+
{
176+
opacity: 1,
177+
y: 0,
178+
},
179+
{
180+
duration: 0.2,
181+
delay: stagger(0.1, {
182+
startDelay: 0.15,
183+
from: count ? count - FETCH_SIZE : 0,
184+
}),
185+
},
186+
)
187+
}, [data])
188+
159189
if (isLoading) <Loading useDefaultLoadingText />
160190

161191
return (
162-
<ul>
192+
<ul ref={scope}>
163193
{data?.pages.map((page) => {
164194
return page.map((item) => {
165195
return (
166196
<li
167197
key={item.id}
168-
className="mb-8 grid grid-cols-[40px_auto] flex-col gap-4 space-y-2"
198+
className="mb-8 grid translate-y-[50px] grid-cols-[40px_auto] flex-col gap-4 space-y-2 opacity-[0.0001]"
169199
>
170200
<div className="translate-y-6">
171201
<img

src/components/layout/header/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const headerMenuConfig: IHeaderMenu[] = [
7474
},
7575

7676
{
77-
title: '其他',
77+
title: '更多',
7878
icon: h(FaSolidCircleNotch),
7979
path: '#',
8080
subMenu: [

src/hooks/common/use-previous.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useEffect, useRef } from 'react'
2+
3+
export const usePrevious = <T>(value: T): (() => T | undefined) => {
4+
const ref = useRef<T>()
5+
useEffect(() => {
6+
ref.current = value
7+
}, [value])
8+
return () => ref.current
9+
}

src/lib/url-builder.ts

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ function isNoteModel(model: any): model is NoteModel {
3333

3434
function buildUrl(model: PostModel | NoteModel | PageModel) {
3535
if (isPostModel(model)) {
36+
// TODO
37+
if (!model.category) {
38+
console.error('PostModel.category is missing!!!!!')
39+
return '#'
40+
}
3641
return `/posts/${
3742
(model.category as CategoryModel).slug
3843
}/${encodeURIComponent(model.slug)}`

0 commit comments

Comments
 (0)