mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-06-28 14:44:15 +00:00
feat: get miis from database and client like button
This commit is contained in:
parent
7b799405dc
commit
8625321ece
5 changed files with 89 additions and 18 deletions
31
src/app/components/like-button.tsx
Normal file
31
src/app/components/like-button.tsx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Icon } from "@iconify/react";
|
||||
|
||||
interface Props {
|
||||
likes: number;
|
||||
isLoggedIn: boolean;
|
||||
}
|
||||
|
||||
export default function LikeButton({ likes, isLoggedIn }: Props) {
|
||||
const [isLiked, setIsLiked] = useState(false);
|
||||
const [likesState, setLikesState] = useState(likes);
|
||||
|
||||
const onClick = () => {
|
||||
if (!isLoggedIn) redirect("/login");
|
||||
|
||||
setIsLiked((prev) => !prev);
|
||||
setLikesState((prev) => (isLiked ? prev - 1 : prev + 1));
|
||||
|
||||
// todo: update database
|
||||
};
|
||||
|
||||
return (
|
||||
<button onClick={onClick} className="flex items-center gap-2 text-xl text-red-400 mt-1 cursor-pointer">
|
||||
<Icon icon={isLiked ? "icon-park-solid:like" : "icon-park-outline:like"} />
|
||||
<span>{likesState}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue