"use client"; import { useState } from "react"; import z from "zod"; import { TextSpeakerArraySchema, TextSpeakerItemSchema, } from "@/lib/interfaces"; import { IconClick } from "@/components/ui/buttons"; import { IMAGES } from "@/config/images"; import { useTranslations } from "next-intl"; import { getLocalStorageOperator } from "@/lib/browser/localStorageOperators"; interface TextCardProps { item: z.infer; handleUse: (item: z.infer) => void; handleDel: (item: z.infer) => void; } function TextCard({ item, handleUse, handleDel }: TextCardProps) { const onUseClick = () => { handleUse(item); }; const onDelClick = () => { handleDel(item); }; return (
{item.text}
{item.ipa}
); } interface SaveListProps { show?: boolean; handleUse: (item: z.infer) => void; } export function SaveList({ show = false, handleUse }: SaveListProps) { const t = useTranslations("text_speaker"); const { get: getFromLocalStorage, set: setIntoLocalStorage } = getLocalStorageOperator( "text-speaker", TextSpeakerArraySchema, ); const [data, setData] = useState(getFromLocalStorage()); const handleDel = (item: z.infer) => { const current_data = getFromLocalStorage(); current_data.splice( current_data.findIndex((v) => v.text === item.text), 1, ); setIntoLocalStorage(current_data); refresh(); }; const refresh = () => { setData(getFromLocalStorage()); }; const handleDeleteAll = () => { const yesorno = prompt(t("confirmDeleteAll"))?.trim(); if (yesorno && (yesorno === "Y" || yesorno === "y")) { setIntoLocalStorage([]); refresh(); } }; if (show) return (
    {data.map((v) => ( ))}
); else return <>; }