import { Plus } from "lucide-react"; import { useState } from "react"; import { Button } from "~/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "~/components/ui/dialog"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "~/components/ui/select"; import { Separator } from "~/components/ui/separator"; import { cn } from "~/lib/utils"; import type { ChatsChatid } from "~/schemas/public/Chats"; import type { EtichetteIdEtichetta } from "~/schemas/public/Etichette"; import { api } from "~/utils/api"; export const EtichetteDisplayer = ({ chatId, className, }: { chatId: ChatsChatid; className?: string; }) => { const { data, isLoading } = api.chat.getChatEtichette.useQuery({ chatId, }); const [openEdit, setOpenEdit] = useState(false); const handleOpen = (status: boolean) => { setOpenEdit(status); }; if ((!isLoading && !data) || !data) return null; return (
{data.map((etichetta) => ( ))}
); }; export const EtichetteModal = ({ chatId, open, onOpenChange, }: { chatId: ChatsChatid; open: boolean; onOpenChange: (status: boolean) => void; }) => { const [selected, setSelected] = useState(null); const utils = api.useUtils(); const { data } = api.chat.getChatEtichette.useQuery({ chatId }); const { data: etichette } = api.etichette.getAllEtichette.useQuery(); const { mutate: remove } = api.chat.removeEtichettaFromChat.useMutation({ onSuccess: async () => { await utils.chat.getChatEtichette.invalidate({ chatId }); await utils.chat.getActiveChats.invalidate(); }, }); const { mutate: add } = api.chat.addEtichettaToChat.useMutation({ onSuccess: async () => { await utils.chat.getChatEtichette.invalidate({ chatId }); await utils.chat.getActiveChats.invalidate(); }, }); if (!data) return null; return ( Etichette Attive Attive
{data.map((etichetta) => (
))}
); }; export const Etichetta = ({ title, color_hex, className, }: { title: string; color_hex: string; className?: string; }) => { return ( {title} ); }; function hexToRgb(hex: string): { r: number; g: number; b: number } { const bigint = parseInt(hex.slice(1), 16); return { b: bigint & 255, g: (bigint >> 8) & 255, r: (bigint >> 16) & 255, }; } export function colorIsDarkSimple(color: string) { if (color === "#FFFFFF") return false; const { r, g, b } = hexToRgb(color); return r * 0.299 + g * 0.587 + b * 0.114 <= 186; }