-
-
Notifications
You must be signed in to change notification settings - Fork 623
ALBUM Feature Added #851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PrathamMehta101
wants to merge
2
commits into
AOSSIE-Org:main
Choose a base branch
from
PrathamMehta101:ALBUM-FEATURE-ADDED
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ALBUM Feature Added #851
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,123 @@ | ||
| import { albumsEndpoints } from '../apiEndpoints'; | ||
| import { apiClient } from '../axiosConfig'; | ||
|
|
||
| interface CreateAlbumPayload { | ||
| name: string; | ||
| description?: string; | ||
| is_hidden?: boolean; | ||
| password?: string; | ||
| } | ||
|
|
||
| export interface Album { | ||
| album_id: string; | ||
| album_name: string; | ||
| description: string; | ||
| is_hidden: boolean; | ||
| } | ||
|
|
||
| interface GetAlbumsResponse { | ||
| success: boolean; | ||
| albums: Album[]; | ||
| } | ||
|
|
||
| export const createAlbum = async (payload: CreateAlbumPayload) => { | ||
| try { | ||
| const response = await apiClient.post(albumsEndpoints.createAlbum, payload); | ||
| return response.data; | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
|
|
||
| export const getAlbums = async (): Promise<GetAlbumsResponse> => { | ||
| try { | ||
| const response = await apiClient.get(albumsEndpoints.getAlbums); | ||
| return response.data; | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
|
|
||
| export const addImagesToAlbum = async (albumId: string, imageIds: string[]) => { | ||
| try { | ||
| const response = await apiClient.post( | ||
| albumsEndpoints.addImagesToAlbum(albumId), | ||
| { | ||
| image_ids: imageIds, | ||
| }, | ||
| ); | ||
| return response.data; | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
|
|
||
| interface GetAlbumImagesResponse { | ||
| success: boolean; | ||
| image_ids: string[]; | ||
| } | ||
|
|
||
| export const getAlbumImages = async ( | ||
| albumId: string, | ||
| password?: string, | ||
| ): Promise<GetAlbumImagesResponse> => { | ||
| try { | ||
| const response = await apiClient.post( | ||
| albumsEndpoints.getAlbumImages(albumId), | ||
| { | ||
| password, | ||
| }, | ||
| ); | ||
| return response.data; | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
|
|
||
| export const removeImageFromAlbum = async ( | ||
| albumId: string, | ||
| imageId: string, | ||
| ) => { | ||
| try { | ||
| const response = await apiClient.delete( | ||
| albumsEndpoints.removeImageFromAlbum(albumId, imageId), | ||
| ); | ||
| return response.data; | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
|
|
||
| export const deleteAlbum = async (albumId: string) => { | ||
| try { | ||
| const response = await apiClient.delete( | ||
| albumsEndpoints.deleteAlbum(albumId), | ||
| ); | ||
| return response.data; | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
|
|
||
| interface UpdateAlbumRequest { | ||
| name: string; | ||
| description?: string; | ||
| is_hidden: boolean; | ||
| current_password?: string; | ||
| password?: string; | ||
| } | ||
|
|
||
| export const updateAlbum = async ( | ||
| albumId: string, | ||
| payload: UpdateAlbumRequest, | ||
| ) => { | ||
| try { | ||
| const response = await apiClient.put( | ||
| albumsEndpoints.updateAlbum(albumId), | ||
| payload, | ||
| ); | ||
| return response.data; | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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,93 @@ | ||
| import { useState, useEffect } from 'react'; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from '@/components/ui/dialog'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { getAlbums, addImagesToAlbum, Album } from '@/api/api-functions'; | ||
|
|
||
| interface AddToAlbumDialogProps { | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| imageIds: string[]; | ||
| } | ||
|
|
||
| export function AddToAlbumDialog({ | ||
| isOpen, | ||
| onClose, | ||
| imageIds, | ||
| }: AddToAlbumDialogProps) { | ||
| const [albums, setAlbums] = useState<Album[]>([]); | ||
| const [loading, setLoading] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| if (isOpen) { | ||
| fetchAlbums(); | ||
| } | ||
| }, [isOpen]); | ||
|
|
||
| const fetchAlbums = async () => { | ||
| try { | ||
| const response = await getAlbums(); | ||
| if (response.success) { | ||
| setAlbums(response.albums); | ||
| } | ||
| } catch (error) { | ||
| console.error('Failed to fetch albums:', error); | ||
| } | ||
| }; | ||
|
|
||
| const handleAddToAlbum = async (albumId: string) => { | ||
| try { | ||
| setLoading(true); | ||
| await addImagesToAlbum(albumId, imageIds); | ||
| // alert('Images added to album successfully!'); | ||
| onClose(); | ||
| } catch (error) { | ||
| console.error('Failed to add images to album:', error); | ||
| alert('Failed to add images to album'); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog open={isOpen} onOpenChange={onClose}> | ||
| <DialogContent className="sm:max-w-[425px]"> | ||
| <DialogHeader> | ||
| <DialogTitle>Add to Album</DialogTitle> | ||
| </DialogHeader> | ||
| <div className="grid gap-4 py-4"> | ||
| {albums.length === 0 ? ( | ||
| <p className="text-muted-foreground text-center"> | ||
| No albums found. | ||
| </p> | ||
| ) : ( | ||
| <div className="grid gap-2"> | ||
| {albums.map((album) => ( | ||
| <Button | ||
| key={album.album_id} | ||
| variant="outline" | ||
| className="justify-start text-left" | ||
| onClick={() => handleAddToAlbum(album.album_id)} | ||
| disabled={loading} | ||
| > | ||
| <div className="flex flex-col items-start gap-1"> | ||
| <span className="font-semibold">{album.album_name}</span> | ||
| {album.description && ( | ||
| <span className="text-muted-foreground text-xs"> | ||
| {album.description} | ||
| </span> | ||
| )} | ||
| </div> | ||
| </Button> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Export CreateAlbumPayload for type safety.
The
CreateAlbumPayloadinterface is not exported, butUpdateAlbumRequest(Line 102) is. For consistency and to enable type-safe usage in consuming components, this interface should also be exported.🔎 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents