From 94ff8c5ec531371d867f0081b1b19eb6f9d1eff9 Mon Sep 17 00:00:00 2001 From: besscroft Date: Fri, 12 Jul 2024 23:00:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E7=85=A7=E7=89=87=E5=88=87=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/BlurImage.tsx | 5 +++-- components/Masonry.tsx | 2 +- components/MasonryItem.tsx | 43 +++++++++++++++++++++++++++++++++++--- stores/buttonStores.ts | 7 +++++++ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/components/BlurImage.tsx b/components/BlurImage.tsx index 4bf2fa2..ca0c3a3 100644 --- a/components/BlurImage.tsx +++ b/components/BlurImage.tsx @@ -4,8 +4,8 @@ import React from 'react' import { useButtonStore } from '~/app/providers/button-store-Providers' import { Image } from '@nextui-org/image' -export default function BlurImage({ photo }: { photo: any }) { - const { setMasonryView, setMasonryViewData } = useButtonStore( +export default function BlurImage({ photo, dataList }: { photo: any, dataList: any }) { + const { setMasonryView, setMasonryViewData, setMasonryViewDataList } = useButtonStore( (state) => state, ) @@ -23,6 +23,7 @@ export default function BlurImage({ photo }: { photo: any }) { onClick={() => { setMasonryView(true) setMasonryViewData(photo) + setMasonryViewDataList(dataList) }} className="duration-700 ease-in-out group-hover:opacity-75 cursor-pointer transition-all will-change-transform hover:scale-[1.01]" /> diff --git a/components/Masonry.tsx b/components/Masonry.tsx index e65aae0..24e41e3 100644 --- a/components/Masonry.tsx +++ b/components/Masonry.tsx @@ -75,7 +75,7 @@ export default function Masonry(props : Readonly) { })) || [] } renderPhoto={({ photo, wrapperStyle, renderDefaultPhoto }) => ( - + )} />
diff --git a/components/MasonryItem.tsx b/components/MasonryItem.tsx index b57df99..d42928b 100644 --- a/components/MasonryItem.tsx +++ b/components/MasonryItem.tsx @@ -7,7 +7,7 @@ import { import { useButtonStore } from '~/app/providers/button-store-Providers' import { CopyrightType, DataProps, ImageType } from '~/types' import { Image, Tabs, Tab, Card, CardHeader, CardBody, CardFooter, Button, Chip, Link, Avatar, Tooltip } from '@nextui-org/react' -import { Aperture, Camera, Image as ImageIcon, Images, Link as LinkIcon, ImageDown, Languages, CalendarDays, X, SunMedium, MoonStar, Copyright, Crosshair, Timer, CircleGauge, Share2 } from 'lucide-react' +import { Aperture, ArrowLeft, ArrowRight, Camera, Image as ImageIcon, Images, Link as LinkIcon, ImageDown, Languages, CalendarDays, X, SunMedium, MoonStar, Copyright, Crosshair, Timer, CircleGauge, Share2 } from 'lucide-react' import * as React from 'react' import { useTheme } from 'next-themes' import { useRouter } from 'next-nprogress-bar' @@ -19,7 +19,7 @@ import useSWR from 'swr' export default function MasonryItem() { const router = useRouter() const pathname = usePathname() - const { MasonryView, MasonryViewData, setMasonryView, setMasonryViewData } = useButtonStore( + const { MasonryView, MasonryViewData, MasonryViewDataList, setMasonryView, setMasonryViewData } = useButtonStore( (state) => state, ) const {data: download = false, mutate: setDownload} = useSWR(['masonry/download', MasonryViewData.url], null) @@ -29,6 +29,20 @@ export default function MasonryItem() { data: MasonryViewData, } + async function loadingHandle(handle: string) { + const idx = MasonryViewDataList.findIndex((item: ImageType) => MasonryViewData.id === item.id) + if (handle === 'next' && idx === MasonryViewDataList.length - 1) { + setMasonryViewData(MasonryViewDataList[0] || MasonryViewData) + } else { + const [prev, next] = [MasonryViewDataList.at(idx-1), MasonryViewDataList.at(idx+1)] + if (handle === 'prev') { + setMasonryViewData(prev || MasonryViewData) + } else { + setMasonryViewData(next || MasonryViewData) + } + } + } + async function downloadImg() { setDownload(true) try { @@ -109,7 +123,30 @@ export default function MasonryItem() { />
- + { + MasonryViewDataList.length > 0 && +
+ + +
+ } + void setMasonryView: (masonryView: boolean) => void setMasonryViewData: (masonryViewData: ImageType) => void + setMasonryViewDataList: (masonryViewDataList: ImageType[]) => void setTagHelp: (tagHelp: boolean) => void setImageHelp: (imageHelp: boolean) => void setUploadHelp: (uploadHelp: boolean) => void @@ -72,6 +74,7 @@ export const initButtonStore = (): ButtonState => { aListData: [] as Config[], MasonryView: false, MasonryViewData: {} as ImageType, + MasonryViewDataList: [] as ImageType[], tagHelp: false, imageHelp: false, uploadHelp: false, @@ -97,6 +100,7 @@ export const defaultInitState: ButtonState = { aListData: [] as Config[], MasonryView: false, MasonryViewData: {} as ImageType, + MasonryViewDataList: [] as ImageType[], tagHelp: false, imageHelp: false, uploadHelp: false, @@ -163,6 +167,9 @@ export const createButtonStore = ( setMasonryViewData: (masonryViewDataValue) => set(() => ({ MasonryViewData: masonryViewDataValue, })), + setMasonryViewDataList: (masonryViewDataListValue) => set(() => ({ + MasonryViewDataList: masonryViewDataListValue, + })), setTagHelp: (tagHelpValue) => set(() => ({ tagHelp: tagHelpValue, })),