Allow ability to choose live layout on mobile

This commit is contained in:
Nicolas Mowen 2024-02-27 11:57:53 -07:00
parent 9e3c9651d3
commit 8d8494de6c
2 changed files with 55 additions and 15 deletions

View File

@ -12,6 +12,7 @@ import useCameraActivity from "@/hooks/use-camera-activity";
import { useRecordingsState } from "@/api/ws"; import { useRecordingsState } from "@/api/ws";
import { LivePlayerMode } from "@/types/live"; import { LivePlayerMode } from "@/types/live";
import useCameraLiveMode from "@/hooks/use-camera-live-mode"; import useCameraLiveMode from "@/hooks/use-camera-live-mode";
import { isDesktop } from "react-device-detect";
type LivePlayerProps = { type LivePlayerProps = {
className?: string; className?: string;
@ -153,7 +154,7 @@ export default function LivePlayer({
className={`bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500`} className={`bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500`}
> >
<MdLeakAdd className="w-4 h-4 text-motion" /> <MdLeakAdd className="w-4 h-4 text-motion" />
<div className="ml-1 text-white text-xs">Motion</div> <div className="hidden md:block ml-1 text-white text-xs">Motion</div>
</Chip> </Chip>
{cameraConfig.audio.enabled_in_config && ( {cameraConfig.audio.enabled_in_config && (
@ -162,11 +163,12 @@ export default function LivePlayer({
className={`bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500`} className={`bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500`}
> >
<BsSoundwave className="w-4 h-4 text-audio" /> <BsSoundwave className="w-4 h-4 text-audio" />
<div className="ml-1 text-white text-xs">Sound</div> <div className="hidden md:block ml-1 text-white text-xs">Sound</div>
</Chip> </Chip>
)} )}
</div> </div>
{isDesktop && (
<Chip className="absolute right-2 top-2 bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500"> <Chip className="absolute right-2 top-2 bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500">
{recording == "ON" && ( {recording == "ON" && (
<MdCircle className="w-2 h-2 drop-shadow-md shadow-danger text-danger" /> <MdCircle className="w-2 h-2 drop-shadow-md shadow-danger text-danger" />
@ -175,6 +177,7 @@ export default function LivePlayer({
{cameraConfig.name.replaceAll("_", " ")} {cameraConfig.name.replaceAll("_", " ")}
</div> </div>
</Chip> </Chip>
)}
</div> </div>
); );
} }

View File

@ -1,17 +1,27 @@
import { useFrigateEvents } from "@/api/ws"; import { useFrigateEvents } from "@/api/ws";
import Logo from "@/components/Logo";
import { AnimatedEventThumbnail } from "@/components/image/AnimatedEventThumbnail"; import { AnimatedEventThumbnail } from "@/components/image/AnimatedEventThumbnail";
import LivePlayer from "@/components/player/LivePlayer"; import LivePlayer from "@/components/player/LivePlayer";
import { Button } from "@/components/ui/button";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
import { TooltipProvider } from "@/components/ui/tooltip"; import { TooltipProvider } from "@/components/ui/tooltip";
import { Event as FrigateEvent } from "@/types/event"; import { Event as FrigateEvent } from "@/types/event";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import { useCallback, useEffect, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
import { isSafari } from "react-device-detect"; import { isDesktop, isMobile, isSafari } from "react-device-detect";
import { LuGrid } from "react-icons/lu";
import { CiGrid2V, CiGrid31 } from "react-icons/ci";
import useSWR from "swr"; import useSWR from "swr";
function Live() { function Live() {
const { data: config } = useSWR<FrigateConfig>("config"); const { data: config } = useSWR<FrigateConfig>("config");
// layout
const [layout, setLayout] = useState<"grid" | "list">(
isDesktop ? "grid" : "list"
);
// recent events // recent events
const { payload: eventUpdate } = useFrigateEvents(); const { payload: eventUpdate } = useFrigateEvents();
const { data: allEvents, mutate: updateEvents } = useSWR<FrigateEvent[]>([ const { data: allEvents, mutate: updateEvents } = useSWR<FrigateEvent[]>([
@ -80,6 +90,31 @@ function Live() {
return ( return (
<div className="w-full h-full overflow-y-scroll px-2"> <div className="w-full h-full overflow-y-scroll px-2">
{isMobile && (
<div className="relative h-9 flex items-center justify-between">
<Logo className="absolute w-full h-8" />
<div />
<div className="flex items-center gap-1">
<Button
className={layout == "grid" ? "text-blue-600 bg-blue-200" : ""}
size="xs"
variant="secondary"
onClick={() => setLayout("grid")}
>
<CiGrid31 className="m-1" />
</Button>
<Button
className={layout == "list" ? "text-blue-600 bg-blue-200" : ""}
size="xs"
variant="secondary"
onClick={() => setLayout("list")}
>
<CiGrid2V className="m-1" />
</Button>
</div>
</div>
)}
{events && events.length > 0 && ( {events && events.length > 0 && (
<ScrollArea> <ScrollArea>
<TooltipProvider> <TooltipProvider>
@ -93,21 +128,23 @@ function Live() {
</ScrollArea> </ScrollArea>
)} )}
<div className="mt-4 md:grid md:grid-cols-2 xl:grid-cols-3 3xl:grid-cols-4 gap-4"> <div
className={`mt-4 grid ${layout == "grid" ? "grid-cols-2 xl:grid-cols-3 3xl:grid-cols-4" : ""} gap-4`}
>
{cameras.map((camera) => { {cameras.map((camera) => {
let grow; let grow;
let aspectRatio = camera.detect.width / camera.detect.height; let aspectRatio = camera.detect.width / camera.detect.height;
if (aspectRatio > 2) { if (aspectRatio > 2) {
grow = "md:col-span-2 aspect-wide"; grow = `${layout == "grid" ? "col-span-2" : ""} aspect-wide`;
} else if (aspectRatio < 1) { } else if (aspectRatio < 1) {
grow = `md:row-span-2 aspect-tall md:h-full`; grow = `${layout == "grid" ? "row-span-2 aspect-tall md:h-full" : ""} aspect-tall`;
} else { } else {
grow = "aspect-video"; grow = "aspect-video";
} }
return ( return (
<LivePlayer <LivePlayer
key={camera.name} key={camera.name}
className={`mb-2 md:mb-0 rounded-2xl bg-black ${grow}`} className={`rounded-2xl bg-black ${grow}`}
windowVisible={windowVisible} windowVisible={windowVisible}
cameraConfig={camera} cameraConfig={camera}
preferredLiveMode={isSafari ? "webrtc" : "mse"} preferredLiveMode={isSafari ? "webrtc" : "mse"}