mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-14 11:02:08 +03:00
add toggle function to mark as unreviewed when all selected are reviewed
This commit is contained in:
parent
b97618a30e
commit
38849c0c9a
@ -1,10 +1,11 @@
|
|||||||
import { FaCircleCheck } from "react-icons/fa6";
|
import { FaCircleCheck, FaCircleXmark } from "react-icons/fa6";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { Button, buttonVariants } from "../ui/button";
|
import { Button, buttonVariants } from "../ui/button";
|
||||||
import { isDesktop } from "react-device-detect";
|
import { isDesktop } from "react-device-detect";
|
||||||
import { FaCompactDisc } from "react-icons/fa";
|
import { FaCompactDisc } from "react-icons/fa";
|
||||||
import { HiTrash } from "react-icons/hi";
|
import { HiTrash } from "react-icons/hi";
|
||||||
|
import { ReviewSegment } from "@/types/review";
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
@ -20,8 +21,8 @@ import { Trans, useTranslation } from "react-i18next";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
type ReviewActionGroupProps = {
|
type ReviewActionGroupProps = {
|
||||||
selectedReviews: string[];
|
selectedReviews: ReviewSegment[];
|
||||||
setSelectedReviews: (ids: string[]) => void;
|
setSelectedReviews: (reviews: ReviewSegment[]) => void;
|
||||||
onExport: (id: string) => void;
|
onExport: (id: string) => void;
|
||||||
pullLatestData: () => void;
|
pullLatestData: () => void;
|
||||||
};
|
};
|
||||||
@ -36,15 +37,24 @@ export default function ReviewActionGroup({
|
|||||||
setSelectedReviews([]);
|
setSelectedReviews([]);
|
||||||
}, [setSelectedReviews]);
|
}, [setSelectedReviews]);
|
||||||
|
|
||||||
const onMarkAsReviewed = useCallback(async () => {
|
const allReviewed = selectedReviews.every(
|
||||||
await axios.post(`reviews/viewed`, { ids: selectedReviews });
|
(review) => review.has_been_reviewed,
|
||||||
|
);
|
||||||
|
|
||||||
|
const onToggleReviewed = useCallback(async () => {
|
||||||
|
const ids = selectedReviews.map((review) => review.id);
|
||||||
|
await axios.post(`reviews/viewed`, {
|
||||||
|
ids,
|
||||||
|
reviewed: !allReviewed,
|
||||||
|
});
|
||||||
setSelectedReviews([]);
|
setSelectedReviews([]);
|
||||||
pullLatestData();
|
pullLatestData();
|
||||||
}, [selectedReviews, setSelectedReviews, pullLatestData]);
|
}, [selectedReviews, setSelectedReviews, pullLatestData, allReviewed]);
|
||||||
|
|
||||||
const onDelete = useCallback(() => {
|
const onDelete = useCallback(() => {
|
||||||
|
const ids = selectedReviews.map((review) => review.id);
|
||||||
axios
|
axios
|
||||||
.post(`reviews/delete`, { ids: selectedReviews })
|
.post(`reviews/delete`, { ids })
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
toast.success(t("recording.confirmDelete.toast.success"), {
|
toast.success(t("recording.confirmDelete.toast.success"), {
|
||||||
@ -140,7 +150,7 @@ export default function ReviewActionGroup({
|
|||||||
aria-label={t("recording.button.export")}
|
aria-label={t("recording.button.export")}
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onExport(selectedReviews[0]);
|
onExport(selectedReviews[0].id);
|
||||||
onClearSelected();
|
onClearSelected();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -154,14 +164,24 @@ export default function ReviewActionGroup({
|
|||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
className="flex items-center gap-2 p-2"
|
className="flex items-center gap-2 p-2"
|
||||||
aria-label={t("recording.button.markAsReviewed")}
|
aria-label={
|
||||||
|
allReviewed
|
||||||
|
? t("recording.button.markAsUnreviewed")
|
||||||
|
: t("recording.button.markAsReviewed")
|
||||||
|
}
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={onMarkAsReviewed}
|
onClick={onToggleReviewed}
|
||||||
>
|
>
|
||||||
<FaCircleCheck className="text-secondary-foreground" />
|
{allReviewed ? (
|
||||||
|
<FaCircleXmark className="text-secondary-foreground" />
|
||||||
|
) : (
|
||||||
|
<FaCircleCheck className="text-secondary-foreground" />
|
||||||
|
)}
|
||||||
{isDesktop && (
|
{isDesktop && (
|
||||||
<div className="text-primary">
|
<div className="text-primary">
|
||||||
{t("recording.button.markAsReviewed")}
|
{allReviewed
|
||||||
|
? t("recording.button.markAsUnreviewed")
|
||||||
|
: t("recording.button.markAsReviewed")}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user