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 f3f535c..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,20 +29,17 @@ export default function MasonryItem() { data: MasonryViewData, } - async function handleOnClick() { - const url = window.location.origin + (pathname === '/' ? '/preview/' : pathname + '/preview/') + MasonryViewData.id - if (navigator.canShare({ url })) { - try { - await navigator.share({ - title: MasonryViewData.title, - text: MasonryViewData.detail, - url: url - }); - } catch (error) { - toast.warning('分享发生错误!', { duration: 500 }) - } + 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 { - toast.warning('您的浏览器不支持!', { duration: 500 }) + const [prev, next] = [MasonryViewDataList.at(idx-1), MasonryViewDataList.at(idx+1)] + if (handle === 'prev') { + setMasonryViewData(prev || MasonryViewData) + } else { + setMasonryViewData(next || MasonryViewData) + } } } @@ -87,21 +84,6 @@ export default function MasonryItem() {

{MasonryViewData.title}

- { - navigator.canShare && typeof navigator.canShare === 'function' && - - - - }
- + { + 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, })),