-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
913 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import Any | ||
|
||
from rest_framework.exceptions import APIException | ||
|
||
|
||
class CustomAPIException(APIException): | ||
def __init__(self, detail: Any, code: str) -> None: | ||
self.code = code | ||
super().__init__({**detail, "code": code}) |
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
74 changes: 74 additions & 0 deletions
74
frontend/src/components/buttons/LevelAddToMyPlaylistButton/index.tsx
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,74 @@ | ||
import { useContext } from "react"; | ||
import { useState } from "react"; | ||
import { useQueryClient } from "react-query"; | ||
import { useQuery } from "react-query"; | ||
import { Button } from "src/components/common/Button"; | ||
import { IconBookmark } from "src/components/icons"; | ||
import { PlaylistItemModal } from "src/components/modals/PlaylistItemModal"; | ||
import { UserContext } from "src/contexts/UserContext"; | ||
import type { LevelNested } from "src/services/LevelService"; | ||
import type { PlaylistItemDetails } from "src/services/PlaylistService"; | ||
import { PlaylistService } from "src/services/PlaylistService"; | ||
import { resetQueries } from "src/utils/misc"; | ||
|
||
interface LevelAddToMyPlaylistButtonProps { | ||
level: LevelNested; | ||
} | ||
|
||
const LevelAddToMyPlaylistButton = ({ | ||
level, | ||
}: LevelAddToMyPlaylistButtonProps) => { | ||
const { user } = useContext(UserContext); | ||
const queryClient = useQueryClient(); | ||
const [isChanged, setIsChanged] = useState(false); | ||
const [isModalActive, setIsModalActive] = useState(false); | ||
|
||
const playlistItemResult = useQuery<PlaylistItemDetails, Error>( | ||
["playlists", PlaylistService.get, user?.id, level.id], | ||
async () => PlaylistService.get(user?.id, level.id) | ||
); | ||
|
||
const handleButtonClick = () => { | ||
setIsModalActive(true); | ||
}; | ||
|
||
const handleSubmit = () => { | ||
setIsChanged(true); | ||
}; | ||
|
||
const handleIsModalActiveChange = (value: boolean) => { | ||
setIsModalActive(value); | ||
if (isChanged) { | ||
resetQueries(queryClient, ["playlists"]); | ||
} | ||
}; | ||
|
||
if (!user) { | ||
return <></>; | ||
} | ||
|
||
if (playlistItemResult.isLoading) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<> | ||
<PlaylistItemModal | ||
isActive={isModalActive} | ||
onIsActiveChange={handleIsModalActiveChange} | ||
user={user} | ||
level={level} | ||
playlistItem={ | ||
(!playlistItemResult.error && playlistItemResult.data) || undefined | ||
} | ||
onSubmit={handleSubmit} | ||
/> | ||
|
||
<Button icon={<IconBookmark />} onClick={handleButtonClick}> | ||
Add to my playlist | ||
</Button> | ||
</> | ||
); | ||
}; | ||
|
||
export { LevelAddToMyPlaylistButton }; |
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
Oops, something went wrong.