mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-17 02:26:43 +03:00
Improve model selection view
This commit is contained in:
parent
8aa260c5cb
commit
cb9dd09929
@ -1,5 +1,6 @@
|
|||||||
import { baseUrl } from "@/api/baseUrl";
|
import { baseUrl } from "@/api/baseUrl";
|
||||||
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||||||
import useOptimisticState from "@/hooks/use-optimistic-state";
|
import useOptimisticState from "@/hooks/use-optimistic-state";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@ -10,6 +11,7 @@ import {
|
|||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { isMobile } from "react-device-detect";
|
import { isMobile } from "react-device-detect";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { FaFolderPlus } from "react-icons/fa";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
const allModelTypes = ["objects", "states"] as const;
|
const allModelTypes = ["objects", "states"] as const;
|
||||||
@ -60,8 +62,8 @@ export default function ModelSelectionView({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex size-full flex-col p-2">
|
<div className="flex size-full flex-col p-2">
|
||||||
<div className="flex h-12 w-full items-center">
|
<div className="flex h-12 w-full items-center justify-between">
|
||||||
<div className="flex flex-row">
|
<div className="flex flex-row items-center">
|
||||||
<ToggleGroup
|
<ToggleGroup
|
||||||
className="*:rounded-md *:px-3 *:py-4"
|
className="*:rounded-md *:px-3 *:py-4"
|
||||||
type="single"
|
type="single"
|
||||||
@ -90,6 +92,12 @@ export default function ModelSelectionView({
|
|||||||
))}
|
))}
|
||||||
</ToggleGroup>
|
</ToggleGroup>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex flex-row items-center">
|
||||||
|
<Button className="flex flex-row items-center gap-2" variant="select">
|
||||||
|
<FaFolderPlus />
|
||||||
|
Add Classification
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex size-full gap-2 p-2">
|
<div className="flex size-full gap-2 p-2">
|
||||||
{classificationConfigs.map((config) => (
|
{classificationConfigs.map((config) => (
|
||||||
@ -113,44 +121,38 @@ function ModelCard({ config, onClick }: ModelCardProps) {
|
|||||||
[id: string]: string[];
|
[id: string]: string[];
|
||||||
}>(`classification/${config.name}/dataset`, { revalidateOnFocus: false });
|
}>(`classification/${config.name}/dataset`, { revalidateOnFocus: false });
|
||||||
|
|
||||||
const coverImages = useMemo(() => {
|
const coverImage = useMemo(() => {
|
||||||
if (!dataset) {
|
if (!dataset) {
|
||||||
return {};
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageMap: { [key: string]: string } = {};
|
const keys = Object.keys(dataset).filter((key) => key != "none");
|
||||||
|
const selectedKey = keys[0];
|
||||||
|
|
||||||
for (const [key, imageList] of Object.entries(dataset)) {
|
return {
|
||||||
if (imageList.length > 0) {
|
name: selectedKey,
|
||||||
imageMap[key] = imageList[0];
|
img: dataset[selectedKey][0],
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return imageMap;
|
|
||||||
}, [dataset]);
|
}, [dataset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={config.name}
|
key={config.name}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-60 cursor-pointer flex-col items-center gap-2 rounded-lg bg-card p-2 outline outline-[3px]",
|
"relative size-60 cursor-pointer overflow-hidden rounded-lg",
|
||||||
"outline-transparent duration-500",
|
"outline-transparent duration-500",
|
||||||
isMobile && "w-full",
|
isMobile && "w-full",
|
||||||
)}
|
)}
|
||||||
onClick={() => onClick()}
|
onClick={() => onClick()}
|
||||||
>
|
>
|
||||||
<div
|
<img
|
||||||
className={cn("grid size-48 grid-cols-2 gap-2", isMobile && "w-full")}
|
className={cn("size-full", isMobile && "w-full")}
|
||||||
>
|
src={`${baseUrl}clips/${config.name}/dataset/${coverImage?.name}/${coverImage?.img}`}
|
||||||
{Object.entries(coverImages).map(([key, image]) => (
|
/>
|
||||||
<img
|
<div className="absolute bottom-0 h-[50%] w-full bg-gradient-to-t from-black/60 to-transparent" />
|
||||||
key={key}
|
<div className="absolute bottom-2 left-3 text-lg smart-capitalize">
|
||||||
className=""
|
{config.name}
|
||||||
src={`${baseUrl}clips/${config.name}/dataset/${key}/${image}`}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="smart-capitalize">{config.name}</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user