1 parent
1132a046f4
commit
34f32e4906
26 files changed
+667
-70
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import "yet-another-react-lightbox/styles.css";
|
||||
|
||||
import { IAsset } from '@/types/asset';
|
||||
import React, { useMemo, useState } from 'react'
|
||||
import Lightbox from 'yet-another-react-lightbox';
|
||||
import { Gallery } from "react-grid-gallery";
|
||||
import LazyGridImage from "../ui/lazy-grid-image";
|
||||
import Download from "yet-another-react-lightbox/plugins/download";
|
||||
|
||||
|
||||
interface AssetGridProps {
|
||||
assets: IAsset[];
|
||||
isInternal?: boolean;
|
||||
selectable?: boolean;
|
||||
}
|
||||
|
||||
export default function AssetGrid({ assets, isInternal = true, selectable = false }: AssetGridProps) {
|
||||
const [index, setIndex] = useState(-1);
|
||||
|
||||
const slides = useMemo(() => {
|
||||
return assets.map((asset) => ({
|
||||
...asset,
|
||||
orientation: 1,
|
||||
src: asset.previewUrl as string,
|
||||
type: (asset.type === "VIDEO" ? "video" : "image") as any,
|
||||
sources:
|
||||
asset.type === "VIDEO"
|
||||
? [
|
||||
{
|
||||
src: asset.downloadUrl as string,
|
||||
type: "video/mp4",
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
height: asset.exifImageHeight as number,
|
||||
width: asset.exifImageWidth as number,
|
||||
downloadUrl: asset.downloadUrl as string,
|
||||
}));
|
||||
}, [assets]);
|
||||
|
||||
console.log(slides);
|
||||
|
||||
const images = useMemo(() => {
|
||||
return assets.map((p) => ({
|
||||
...p,
|
||||
src: p.url as string,
|
||||
original: p.previewUrl as string,
|
||||
width: p.exifImageWidth / 10 as number,
|
||||
height: p.exifImageHeight / 10 as number,
|
||||
orientation: 1
|
||||
}));
|
||||
}, [assets]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Lightbox
|
||||
slides={slides}
|
||||
plugins={[Download]}
|
||||
open={index >= 0}
|
||||
index={index}
|
||||
close={() => setIndex(-1)}
|
||||
/>
|
||||
<Gallery
|
||||
images={images}
|
||||
onClick={setIndex}
|
||||
enableImageSelection={selectable}
|
||||
thumbnailImageComponent={LazyGridImage}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import React, { useState } from 'react'
|
||||
import { Dialog, DialogTitle, DialogContent, DialogHeader, DialogTrigger, DialogDescription } from '../ui/dialog';
|
||||
import { Button, ButtonProps } from '../ui/button';
|
||||
import { ShareLinkFilters } from '@/types/shareLink';
|
||||
import { generateShareLink } from '@/handlers/api/shareLink.handler';
|
||||
import { Input } from '../ui/input';
|
||||
import { Label } from '@radix-ui/react-label';
|
||||
|
||||
|
||||
interface ShareAssetsTriggerProps {
|
||||
filters: ShareLinkFilters
|
||||
buttonProps?: ButtonProps
|
||||
}
|
||||
|
||||
export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssetsTriggerProps) {
|
||||
const [generatedLink, setGeneratedLink] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const handleGenerate = async () => {
|
||||
setLoading(true);
|
||||
return generateShareLink(filters).then(({ link }) => {
|
||||
setGeneratedLink(link);
|
||||
}).catch((err) => {
|
||||
setErrorMessage(err.message);
|
||||
}).finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
|
||||
const handleCopy = () => {
|
||||
if (generatedLink) {
|
||||
navigator.clipboard.writeText(generatedLink);
|
||||
setCopied(true);
|
||||
setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button {...buttonProps}>Share</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Share Assets</DialogTitle>
|
||||
</DialogHeader>
|
||||
<DialogDescription>
|
||||
Share your assets with your friends and family.
|
||||
</DialogDescription>
|
||||
{errorMessage && <div className="text-red-500">{errorMessage}</div>}
|
||||
{generatedLink ? <div className="flex flex-col gap-2">
|
||||
<Label className='text-sm'>Share Link</Label>
|
||||
<Input readOnly type="text" value={generatedLink} />
|
||||
<p className='text-xs text-muted-foreground'>
|
||||
This is a stateless link, it will not work if you leave the page. Which means it cannot be expired.
|
||||
</p>
|
||||
<Button onClick={handleCopy}>{copied ? 'Copied' : 'Copy'}</Button>
|
||||
</div> : (
|
||||
<Button onClick={handleGenerate} disabled={loading}>Generate Share Link</Button>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user