Skip to content

Commit

Permalink
Merge pull request #19 from ChaiyoKung/ui/appsweb-add-video-file-preview
Browse files Browse the repository at this point in the history
[apps/web] Add video file preview
  • Loading branch information
ChaiyoKung authored Aug 19, 2024
2 parents a96ad53 + dc57eb5 commit 447efc7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
11 changes: 11 additions & 0 deletions apps/web/components/LocalVideo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useMemo } from "react";

interface LocalVideoProps extends React.ComponentPropsWithoutRef<"video"> {
path: string;
}

export default function LocalVideo({ path, ...props }: LocalVideoProps) {
const src = useMemo(() => `/api/files?path=${encodeURIComponent(path)}`, [path]);

return <video src={src} {...props} />;
}
7 changes: 2 additions & 5 deletions apps/web/src/app/_components/FilePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useLookupFile from "../../../hooks/useLookupFile";
import { LocalImage } from "../../../components/LocalImage";
import LocalVideo from "../../../components/LocalVideo";

interface FilePreviewProps {
path: string;
Expand Down Expand Up @@ -45,11 +46,7 @@ export function FilePreview({ path }: FilePreviewProps) {
}

if (data.startsWith("video")) {
return (
<div className="text-yellow-500 bg-yellow-100 rounded-xl border border-yellow-300 border-dashed p-2 w-full">
{data}
</div>
);
return <LocalVideo path={path} controls className="rounded-xl max-h-48" />;
}

return (
Expand Down
Binary file added demo/loop.mp4
Binary file not shown.
Binary file added demo/sub/loop.mp4
Binary file not shown.

0 comments on commit 447efc7

Please sign in to comment.