Skip to content

Commit

Permalink
refactor: say page strutrue
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Apr 2, 2024
1 parent b59f029 commit 5f72c6b
Show file tree
Hide file tree
Showing 22 changed files with 201 additions and 155 deletions.
6 changes: 4 additions & 2 deletions src/app/(app)/(home)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import { PeekLink } from '~/components/modules/peek/PeekLink'
import { PostMetaBar } from '~/components/modules/post'
import { MotionButtonBase } from '~/components/ui/button'
import { RelativeTime } from '~/components/ui/relative-time'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import { TextUpTransitionView } from '~/components/ui/transition/TextUpTransitionView'
import {
BottomToUpTransitionView,
TextUpTransitionView,
} from '~/components/ui/transition'
import {
microReboundPreset,
softBouncePreset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { useParams } from 'next/navigation'
import { LoadMoreIndicator } from '~/components/modules/shared/LoadMoreIndicator'
import { TimelineList } from '~/components/ui/list/TimelineList'
import { Loading } from '~/components/ui/loading'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import {
BottomToUpSoftScaleTransitionView,
BottomToUpTransitionView,
} from '~/components/ui/transition'
import { apiClient } from '~/lib/request'
import { routeBuilder, Routes } from '~/lib/route-builder'

Expand Down
6 changes: 4 additions & 2 deletions src/app/(app)/(note-topic)/notes/topics/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { useQuery } from '@tanstack/react-query'
import Link from 'next/link'

import { TimelineList } from '~/components/ui/list/TimelineList'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import {
BottomToUpSoftScaleTransitionView,
BottomToUpTransitionView,
} from '~/components/ui/transition'
import { routeBuilder, Routes } from '~/lib/route-builder'

import { topicsQuery } from './query'
Expand Down
6 changes: 4 additions & 2 deletions src/app/(app)/(page-detail)/[slug]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import {
} from '~/components/modules/activity'
import { CommentAreaRootLazy } from '~/components/modules/comment'
import { TocFAB } from '~/components/modules/toc/TocFAB'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import {
BottomToUpSoftScaleTransitionView,
BottomToUpTransitionView,
} from '~/components/ui/transition'
import { OnlyMobile } from '~/components/ui/viewport/OnlyMobile'
import { attachUAAndRealIp } from '~/lib/attach-ua'
import { getOgUrl } from '~/lib/helper.server'
Expand Down
6 changes: 4 additions & 2 deletions src/app/(app)/categories/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { useParams } from 'next/navigation'

import { BackToTopFAB } from '~/components/ui/fab'
import { TimelineList } from '~/components/ui/list/TimelineList'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import {
BottomToUpSoftScaleTransitionView,
BottomToUpTransitionView,
} from '~/components/ui/transition'
import { routeBuilder, Routes } from '~/lib/route-builder'

import { getPageBySlugQuery } from './query'
Expand Down
2 changes: 1 addition & 1 deletion src/app/(app)/friends/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { BackToTopFAB } from '~/components/ui/fab'
import { Form, FormInput } from '~/components/ui/form'
import { Loading } from '~/components/ui/loading'
import { useModalStack } from '~/components/ui/modal'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import { BottomToUpTransitionView } from '~/components/ui/transition'
import { shuffle } from '~/lib/lodash'
import { apiClient, getErrorMessageFromRequestError } from '~/lib/request'
import { toast } from '~/lib/toast'
Expand Down
2 changes: 1 addition & 1 deletion src/app/(app)/notes/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CommentAreaRootLazy } from '~/components/modules/comment'
import { NoteFontSettingFab } from '~/components/modules/note/NoteFontFab'
import { NoteMainContainer } from '~/components/modules/note/NoteMainContainer'
import { TocFAB } from '~/components/modules/toc/TocFAB'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition'
import { OnlyMobile } from '~/components/ui/viewport/OnlyMobile'
import { getOgUrl } from '~/lib/helper.server'
import { getSummaryFromMd } from '~/lib/markdown'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import type { PageParams } from './api'
import { buildRoomName, RoomProvider } from '~/components/modules/activity'
import { CommentAreaRootLazy } from '~/components/modules/comment'
import { TocFAB } from '~/components/modules/toc/TocFAB'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import {
BottomToUpSoftScaleTransitionView,
BottomToUpTransitionView,
} from '~/components/ui/transition'
import { OnlyMobile } from '~/components/ui/viewport/OnlyMobile'
import { getOgUrl } from '~/lib/helper.server'
import { getSummaryFromMd } from '~/lib/markdown'
Expand Down
2 changes: 1 addition & 1 deletion src/app/(app)/posts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PostPagination } from '~/components/modules/post/PostPagination'
import { NothingFound } from '~/components/modules/shared/NothingFound'
import { SearchFAB } from '~/components/modules/shared/SearchFAB'
import { BackToTopFAB } from '~/components/ui/fab'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import { BottomToUpTransitionView } from '~/components/ui/transition'
import { OnlyDesktop } from '~/components/ui/viewport'
import { apiClient } from '~/lib/request'

Expand Down
2 changes: 1 addition & 1 deletion src/app/(app)/projects/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GitHubBrandIcon } from '~/components/icons/platform/GitHubBrandIcon'
import { ProjectList } from '~/components/modules/project/ProjectList'
import { NothingFound } from '~/components/modules/shared/NothingFound'
import { Loading } from '~/components/ui/loading'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import { BottomToUpTransitionView } from '~/components/ui/transition'
import { noopArr } from '~/lib/noop'
import { apiClient } from '~/lib/request'
import { useAggregationSelector } from '~/providers/root/aggregation-data-provider'
Expand Down
137 changes: 6 additions & 131 deletions src/app/(app)/says/page.tsx
Original file line number Diff line number Diff line change
@@ -1,153 +1,28 @@
'use client'

import { useInfiniteQuery } from '@tanstack/react-query'
import { memo, useMemo } from 'react'
import { m } from 'framer-motion'
import Markdown from 'markdown-to-jsx'
import type { SayModel } from '@mx-space/api-client'
import type { MarkdownToJSX } from 'markdown-to-jsx'

import { useIsMobile } from '~/atoms/hooks'
import { LoadMoreIndicator } from '~/components/modules/shared/LoadMoreIndicator'
import { useSayListQuery } from '~/components/modules/say/hooks'
import { SayMasonry } from '~/components/modules/say/SayMasonry'
import { NothingFound } from '~/components/modules/shared/NothingFound'
import { Loading } from '~/components/ui/loading'
import { Masonry } from '~/components/ui/masonry'
import { RelativeTime } from '~/components/ui/relative-time'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
import { useIsDark } from '~/hooks/common/use-is-dark'
import { addAlphaToHSL, getColorScheme, stringToHue } from '~/lib/color'
import { apiClient } from '~/lib/request'

import { sayQueryKey } from './query'
import { FullPageLoading } from '~/components/ui/loading'

export default function Page() {
const { fetchNextPage, hasNextPage, data, isLoading } = useInfiniteQuery({
queryKey: sayQueryKey,
queryFn: async ({ pageParam }) => {
const data = await apiClient.say.getAllPaginated(pageParam)
return data
},
initialPageParam: 1,
getNextPageParam: (lastPage) =>
lastPage.pagination.hasNextPage
? lastPage.pagination.currentPage + 1
: undefined,
})

const isMobile = useIsMobile()
const { data, isLoading } = useSayListQuery()

if (isLoading) {
return <Loading useDefaultLoadingText />
return <FullPageLoading />
}

if (!data || data.pages.length === 0) return <NothingFound />

const list = data.pages
.map((page) => page.data)
.flat()
.map((say) => {
return {
text: say.text,
item: say,
id: say.id,
}
})

return (
<div>
<header className="prose">
<h1>一言</h1>
</header>

<main className="mt-10">
<Masonry Component={Item} columns={isMobile ? 1 : 2} list={list} />

{hasNextPage && (
<LoadMoreIndicator onLoading={fetchNextPage} className="mt-12">
<BottomToUpSoftScaleTransitionView>
<Masonry
Component={SaySkeleton}
columns={isMobile ? 1 : 2}
list={placeholderData}
/>
</BottomToUpSoftScaleTransitionView>
</LoadMoreIndicator>
)}
<SayMasonry />
</main>
</div>
)
}
const placeholderData = Array.from({ length: 10 }).map((_, index) => ({
index,
text: '',
id: index.toFixed(),
item: {} as SayModel,
}))
const SaySkeleton = memo(() => {
return (
<div className="relative mb-4 border-l-[3px] border-l-slate-500 bg-slate-200/50 px-4 py-3 dark:bg-neutral-800">
<div className="mb-2 h-6 w-full rounded bg-slate-300/80 dark:bg-neutral-700" />
<div className="flex text-sm text-base-content/60 md:justify-between">
<div className="mb-2 h-4 w-14 rounded bg-slate-300/80 dark:bg-neutral-700 md:mb-0" />
<div className="ml-auto text-right">
<div className="h-4 w-1/4 rounded bg-slate-300/80 dark:bg-neutral-700" />
</div>
</div>
</div>
)
})
SaySkeleton.displayName = 'SaySkeleton'

const options = {
disableParsingRawHTML: true,
forceBlock: true,
} satisfies MarkdownToJSX.Options

const Item = memo<{
item: SayModel
index: number
}>(({ item: say, index: i }) => {
const hasSource = !!say.source
const hasAuthor = !!say.author
// const color = colorsMap.get(say.id)
const { dark: darkColors, light: lightColors } = useMemo(
() => getColorScheme(stringToHue(say.id)),
[say.id],
)
const isDark = useIsDark()

return (
<BottomToUpTransitionView delay={i * 50} key={say.id}>
<m.blockquote
layout
key={say.id}
className="mb-4 border-l-[3px] px-4 py-3"
style={{
borderLeftColor: isDark ? darkColors.accent : lightColors.accent,
backgroundColor: addAlphaToHSL(
isDark ? darkColors.background : lightColors.background,
0.15,
),
}}
>
<Markdown className="mb-2" options={options}>{`${say.text}`}</Markdown>
<div className="flex flex-wrap text-sm text-base-content/60 md:justify-between">
<div className="mb-2 w-full md:mb-0 md:w-auto">
<span className="mr-2">发布于</span>
<RelativeTime date={say.created} />
</div>
<div className="w-full text-right md:ml-auto md:w-auto">
<div>
{hasSource && `出自“${say.source}”`}
{hasSource && hasAuthor && ', '}
{hasAuthor && `作者:${say.author}`}
{!hasAuthor && !hasSource && '站长说'}
</div>
</div>
</div>
</m.blockquote>
</BottomToUpTransitionView>
)
})
Item.displayName = 'Item'
1 change: 0 additions & 1 deletion src/app/(app)/says/query.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/(app)/timeline/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { TimelineProgress } from '~/components/modules/timeline/TimelineProgress
import { Divider } from '~/components/ui/divider'
import { BackToTopFAB } from '~/components/ui/fab'
import { TimelineList } from '~/components/ui/list/TimelineList'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition'
import { apiClient } from '~/lib/request'
import { springScrollToElement } from '~/lib/scroller'

Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/comment/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { CommentBaseProps } from './types'

import { ErrorBoundary } from '~/components/common/ErrorBoundary'
import { NotSupport } from '~/components/common/NotSupport'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition'
import { apiClient } from '~/lib/request'

import { LoadMoreIndicator } from '../shared/LoadMoreIndicator'
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/note/NoteTimelineItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Link from 'next/link'
import { tv } from 'tailwind-variants'
import type { Target, TargetAndTransition } from 'framer-motion'

import { LeftToRightTransitionView } from '~/components/ui/transition/LeftToRightTransitionView'
import { LeftToRightTransitionView } from '~/components/ui/transition'
import { clsxm } from '~/lib/helper'
import { routeBuilder, Routes } from '~/lib/route-builder'
import { springScrollToTop } from '~/lib/scroller'
Expand Down
Loading

0 comments on commit 5f72c6b

Please sign in to comment.