import { useCallback, useEffect, useState } from "react"; import { Button, OverlayTrigger, Tooltip } from "react-bootstrap"; import { ToastContainer } from "react-toastify"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faThumbsUp, faThumbsDown, faTrash, faPlus, faGear } from "@fortawesome/free-solid-svg-icons"; import Header from "../components/Header"; import Footer from "../components/Footer"; import Loader from "../components/Loader"; import { useAuth } from "../context/auth"; import Login from "../Login"; import AddSuggestionModal from "../components/modals/AddSuggestionModal"; import SuggestionDetailModal from "../components/modals/SuggestionDetailModal"; import { Suggestion, VoteDirection, listSuggestions, addSuggestion, voteSuggestion, deleteSuggestion, } from "../../../types"; import "./SuggestionsPage.scss"; export default function SuggestionsPage() { const auth = useAuth(); const [suggestions, setSuggestions] = useState(); const [addModalOpen, setAddModalOpen] = useState(false); const [detail, setDetail] = useState(); const reload = useCallback(async () => { if (!auth?.login) return; const response = await listSuggestions(); setSuggestions(response.data ?? []); }, [auth?.login]); useEffect(() => { reload(); }, [reload]); const handleAdd = async (title: string, description: string) => { const response = await addSuggestion({ body: { title, description } }); if (response.data) { setSuggestions(response.data); } }; const handleVote = async (id: string, direction: VoteDirection) => { const response = await voteSuggestion({ body: { id, direction } }); if (response.data) { setSuggestions(response.data); } }; const handleDelete = async (suggestion: Suggestion) => { if (!window.confirm(`Opravdu chcete smazat návrh „${suggestion.title}“? Smažou se i všechny jeho hlasy.`)) { return; } const response = await deleteSuggestion({ body: { id: suggestion.id } }); if (response.data) { setSuggestions(response.data); } }; // Vykreslí jeden řádek tabulky. Vyřešené návrhy jsou read-only (bez hlasování), // ale autor je stále může smazat. const renderRow = (suggestion: Suggestion) => ( {suggestion.description}} > setDetail(suggestion)}> {suggestion.author} {suggestion.title} {suggestion.voteScore} e.stopPropagation()}> {!suggestion.resolved && ( <> )} {suggestion.isMine && ( )} ); if (!auth?.login) { return ; } if (!suggestions) { return ; } const activeSuggestions = suggestions.filter(s => !s.resolved); const resolvedSuggestions = suggestions.filter(s => s.resolved); return ( <>

Návrhy na vylepšení

Zde můžete navrhovat vylepšení aplikace a hlasovat o návrzích ostatních. U každého návrhu je zobrazeno jméno navrhovatele. Jména hlasujících jsou dostupná pouze administrátorům.

{suggestions.length === 0 ? (

Zatím nebyly přidány žádné návrhy. Buďte první!

) : ( <> {activeSuggestions.length > 0 && ( {activeSuggestions.map(renderRow)}
Navrhovatel Název Hlasy Akce
)} {resolvedSuggestions.length > 0 && (

Vyřešené návrhy

Tyto návrhy již byly zapracovány. Nelze pro ně hlasovat, autor je však může odstranit.

{resolvedSuggestions.map(renderRow)}
Navrhovatel Název Hlasy Akce
)} )}