-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from varun-raj/feat-albums-enhancement
Feat: Albums enhancement and ux enhancements
- Loading branch information
Showing
41 changed files
with
1,074 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { Button } from '@/components/ui/button'; | ||
import { Checkbox } from '@/components/ui/checkbox'; | ||
import { Dialog, DialogTitle, DialogHeader, DialogContent } from '@/components/ui/dialog'; | ||
import { Label } from '@/components/ui/label'; | ||
import { shareAlbums } from '@/handlers/api/album.handler'; | ||
import { IAlbum } from '@/types/album'; | ||
import React, { ForwardedRef, forwardRef, useImperativeHandle, useState } from 'react' | ||
|
||
export interface IAlbumShareDialogProps { | ||
|
||
} | ||
|
||
export interface IAlbumShareDialogRef { | ||
open: (selectedAlbums: IAlbum[]) => void; | ||
close: () => void; | ||
} | ||
|
||
interface IAlbumWithLink extends IAlbum { | ||
shareLink?: string; | ||
allowDownload?: boolean; | ||
allowUpload?: boolean; | ||
showMetadata?: boolean; | ||
} | ||
|
||
const AlbumShareDialog = forwardRef(({ }: IAlbumShareDialogProps, ref: ForwardedRef<IAlbumShareDialogRef>) => { | ||
const [open, setOpen] = useState(false); | ||
const [selectedAlbums, setSelectedAlbums] = useState<IAlbumWithLink[]>([]); | ||
const [generating, setGenerating] = useState(false); | ||
const [error, setError] = useState<string | null>(null); | ||
const [generated, setGenerated] = useState<boolean>(false); | ||
|
||
const handleGenerateShareLink = async () => { | ||
setGenerating(true); | ||
const data = selectedAlbums.map((album) => ({ | ||
albumId: album.id, | ||
albumName: album.albumName, | ||
assetCount: album.assetCount, | ||
allowDownload: !!album.allowDownload, | ||
allowUpload: !!album.allowUpload, | ||
showMetadata: !!album.showMetadata, | ||
})); | ||
|
||
return shareAlbums(data).then((updatedAlbums) => { | ||
setSelectedAlbums(updatedAlbums); | ||
setGenerated(true); | ||
}) | ||
.catch((error) => { | ||
setError(error.message); | ||
}) | ||
.finally(() => { | ||
setGenerating(false); | ||
}); | ||
} | ||
|
||
const handleAllowPropertyChange = (albumId: string, property: string, checked: boolean) => { | ||
setSelectedAlbums((prevAlbums) => prevAlbums.map((album) => album.id === albumId ? { ...album, [property]: checked } : album)); | ||
} | ||
|
||
|
||
useImperativeHandle(ref, () => ({ | ||
open: (selectedAlbums: IAlbum[]) => { | ||
setSelectedAlbums(selectedAlbums.map((album) => ({ ...album, allowDownload: true, allowUpload: true, showMetadata: true }))); | ||
setOpen(true); | ||
}, | ||
close: () => { | ||
setOpen(false); | ||
} | ||
})); | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogContent className="max-w-4xl"> | ||
<DialogHeader> | ||
<DialogTitle>Share {selectedAlbums.length} albums</DialogTitle> | ||
</DialogHeader> | ||
<div className="flex flex-col gap-2"> | ||
{error && <div className="text-red-500">{error}</div>} | ||
<ol className="flex flex-col gap-4 list-decimal px-4 py-4"> | ||
{selectedAlbums.map((album) => ( | ||
<li key={album.id}> | ||
<div className="flex justify-between gap-1"> | ||
<h3 className="text-sm font-medium">{album.albumName}</h3> | ||
<p className="text-xs border truncate rounded-md px-1 py-0.5 text-muted-foreground">{album.assetCount} Items</p> | ||
</div> | ||
<div className="flex flex-col gap-2"> | ||
{album.shareLink ? | ||
<p className="text-xs text-muted-foreground truncate font-mono overflow-x-auto">{album.shareLink}</p> : ( | ||
<> | ||
<p className="text-xs text-muted-foreground">No share link generated</p> | ||
<div className="flex gap-2"> | ||
<div className="flex items-center gap-1"> | ||
<Checkbox checked={album.allowDownload} onCheckedChange={(checked) => handleAllowPropertyChange(album.id, 'allowDownload', !!checked)} /> | ||
<Label className="text-xs">Allow Download</Label> | ||
</div> | ||
<div className="flex items-center gap-1"> | ||
<Checkbox checked={album.allowUpload} onCheckedChange={(checked) => handleAllowPropertyChange(album.id, 'allowUpload', !!checked)} /> | ||
<Label className="text-xs">Allow Upload</Label> | ||
</div> | ||
<div className="flex items-center gap-1"> | ||
<Checkbox checked={album.showMetadata} onCheckedChange={(checked) => handleAllowPropertyChange(album.id, 'showMetadata', !!checked)} /> | ||
<Label className="text-xs">Show Metadata</Label> | ||
</div> | ||
|
||
</div> | ||
</> | ||
)} | ||
</div> | ||
</li> | ||
|
||
))} | ||
</ol> | ||
{generated ? ( | ||
<> | ||
<p className="text-sm py-2 text-muted-foreground text-center">Share links all generated</p> | ||
</> | ||
) : ( | ||
<> | ||
{generating ? <div className="flex justify-center gap-2"> | ||
<p className="text-sm py-2 text-muted-foreground">Generating share links...</p> | ||
</div> : <div className="flex justify-center gap-2"> | ||
<Button onClick={handleGenerateShareLink} disabled={generating}> | ||
Generate For {selectedAlbums.length} albums | ||
</Button> | ||
|
||
</div>} | ||
</> | ||
)} | ||
|
||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
}) | ||
|
||
AlbumShareDialog.displayName = "AlbumShareDialog"; | ||
|
||
export default AlbumShareDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.