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

0.6.0 #10

Merged
merged 4 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions components/Masonry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ export default function Masonry(props : Readonly<ImageHandleProps>) {
</div>
)}
/>
{isValidating && <Spinner label="Loading..." color="primary" className="mx-auto w-full my-6" />}
<div className="flex items-center justify-center my-4">
{
size < pageTotal ?
isValidating ?
<Spinner label="Loading..." color="primary" />
:
size < pageTotal &&
<Button
color="primary"
variant="bordered"
Expand All @@ -76,8 +78,6 @@ export default function Masonry(props : Readonly<ImageHandleProps>) {
>
加载更多
</Button>
:
<></>
}
</div>
<MasonryItem />
Expand Down
4 changes: 3 additions & 1 deletion components/layout/DynamicDropMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default function DynamicDropMenu(props: Readonly<HandleProps>) {
const pathname = usePathname()
const { data } = useSWRHydrated(props)

console.log(data)

return (
<Dropdown shadow="sm" backdrop="blur">
<DropdownTrigger>
Expand All @@ -27,7 +29,7 @@ export default function DynamicDropMenu(props: Readonly<HandleProps>) {
>
首页
</DropdownItem>
{data && data?.map((tag: TagType, index: any, array: TagType[]) => (
{data && Array.isArray(data) && data?.map((tag: TagType, index: any, array: TagType[]) => (
<DropdownItem
key={tag.id}
onClick={() => router.push(tag.tag_value)}
Expand Down
9 changes: 6 additions & 3 deletions components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import Logo from '~/components/layout/Logo'
import DynamicNavbar from '~/components/layout/DynamicNavbar'
import HeaderLink from '~/components/layout/HeaderLink'
import { fetchTagsShow } from '~/server/lib/query'
import { HandleProps } from '~/types'
import { LinkProps } from '~/types'

export default function Header() {
export default async function Header() {
const getData = async () => {
'use server'
return await fetchTagsShow()
}

const props: HandleProps = {
const data = await getData()

const props: LinkProps = {
handle: getData,
args: 'headerLink',
data: data
}

return (
Expand Down
13 changes: 8 additions & 5 deletions components/layout/HeaderLink.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
'use client'

import { Button } from '@nextui-org/react'
import { TagType, HandleProps } from '~/types'
import { useSWRHydrated } from '~/hooks/useSWRHydrated'
import { TagType, LinkProps } from '~/types'
import { usePathname } from 'next/navigation'
import { useRouter } from 'next-nprogress-bar'
import useSWR from 'swr'

export default function HeaderLink(props: Readonly<HandleProps>) {
const { data } = useSWRHydrated(props)
export default function HeaderLink(props: Readonly<LinkProps>) {
const { data } = useSWR(props.args,
() => {
return props.handle
}, { revalidateOnFocus: false, fallbackData: props.data })
const pathname = usePathname()
const router = useRouter()

Expand All @@ -22,7 +25,7 @@ export default function HeaderLink(props: Readonly<HandleProps>) {
>
首页
</Button>
{data?.map((tag: TagType) => (
{Array.isArray(data) && data?.map((tag: TagType) => (
<Button
key={tag.id}
color="primary"
Expand Down
6 changes: 6 additions & 0 deletions instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export async function register() {
],
skipDuplicates: true,
})
await tx.tags.createMany({
data: [
{ name: '首页', tag_value: '/', detail: '首页,勿删', show: 0, sort: 0 },
],
skipDuplicates: true,
})
})
console.log('初始化完毕!')
await prisma.$disconnect()
Expand Down
1 change: 1 addition & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type ImageHandleProps = {
export type LinkProps = {
handle: () => any
args: string
data: any
}

export type TagType = {
Expand Down
Loading