diff --git a/src/components/Sidebar.astro b/src/components/Sidebar.astro index 753f953..66831f6 100644 --- a/src/components/Sidebar.astro +++ b/src/components/Sidebar.astro @@ -11,6 +11,7 @@ import SidebarSection from './sidebar/SidebarSection.astro' import Highlight from './sidebar/Highlight.astro' import AlbumBox from './AlbumBox.astro' import AlbumCount from './sidebar/AlbumCount.astro' +import CommentCarousel from './sidebar/CommentCarousel.astro' const listClass = 'uppercase text-3xl font-semibold w-full text-center py-3 hover:bg-dark-hover hover:text-cyan-400 hover:underline' @@ -48,6 +49,9 @@ const listClass = + + + diff --git a/src/components/sidebar/CommentCarousel.astro b/src/components/sidebar/CommentCarousel.astro new file mode 100644 index 0000000..d638047 --- /dev/null +++ b/src/components/sidebar/CommentCarousel.astro @@ -0,0 +1,27 @@ +--- +import prismaClient from 'utils/prisma-client' +import { Icon } from 'astro-icon/components' + +import SidebarSection from './SidebarSection.astro' +import Looper from './CommentCarousel/Looper' + +const comments = await prismaClient.comments.findMany({ + select: { text: true, albums: { select: { id: true, title: true } } }, + orderBy: { createdAt: 'desc' }, + take: 5 +}) +--- + + + + + + + diff --git a/src/components/sidebar/CommentCarousel/Looper.tsx b/src/components/sidebar/CommentCarousel/Looper.tsx new file mode 100644 index 0000000..66ae6f2 --- /dev/null +++ b/src/components/sidebar/CommentCarousel/Looper.tsx @@ -0,0 +1,58 @@ +import clsx from 'clsx' +import { useEffect, useRef, useState, type ButtonHTMLAttributes, type ReactNode } from 'react' + +interface Props { + comments: { + text: string | null + albums: { + id: number + title: string | null + } | null + }[] +} + +function ArrowButton(props: ButtonHTMLAttributes) { + const { className, ...rest } = props + + return +} + +export default function Looper(props: Props) { + //@ts-ignore + const { comments, arrowRight, arrowLeft } = props + const [index, setIndex] = useState(0) + const timeoutRef = useRef | null>(null) + + const nextIndex = index === comments.length - 1 ? 0 : index + 1 + const pastIndex = index === 0 ? comments.length - 1 : index - 1 + const isMultiple = comments.length >= 2 + const comment = comments[index] + + useEffect(() => { + if (timeoutRef.current) clearTimeout(timeoutRef.current) + timeoutRef.current = setTimeout(() => setIndex(nextIndex), 10 * 1000) + }, [index]) + + return ( + + {comment.text} + + -{' '} + + {comment.albums?.title} + + + {isMultiple ? ( + + setIndex(pastIndex)}>{arrowLeft} + + {index + 1} / {comments.length} + + setIndex(nextIndex)}>{arrowRight} + + ) : ( + false + )} + + ) +} diff --git a/src/img/icons/arrow-right.svg b/src/img/icons/arrow-right.svg new file mode 100644 index 0000000..4a3a010 --- /dev/null +++ b/src/img/icons/arrow-right.svg @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file