-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spike: saving artworks to lists on other grids (#11978)
* feat: add ManagerArtworkForCollections * feat: add `SaveArtworkToCollectionsButton` * feat: initially render custom save button * chore: pass `onSave` prop in `GridItem` * fix: typo in name * feat: show modal when save button is pressed * refactor: keep only artwork id * feat: pass `collectionId` to `GridItem` * refactor: rename field * feat: keep savedListId in context * feat: add `ManageArtworkForCollectionsProvider` component * feat: restore save logic * refactor: fixes * refactor: rename * chore: add comment * feat: add `enableSaveButtonForLists` prop * refactor: remove unused component * refactor: imrpovements, restore some prev code * chore: update comment Co-authored-by: Anandaroop Roy <anandaroop.roy+github@gmail.com> --------- Co-authored-by: Anandaroop Roy <anandaroop.roy+github@gmail.com>
- Loading branch information
1 parent
babafae
commit 852303a
Showing
153 changed files
with
747 additions
and
539 deletions.
There are no files selected for viewing
59 changes: 0 additions & 59 deletions
59
src/Apps/CollectorProfile/Routes/Saves2/Components/SavesArtworkSaveButton.tsx
This file was deleted.
Oops, something went wrong.
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,78 @@ | ||
import { SelectListsForArtworkModalQueryRender } from "Apps/CollectorProfile/Routes/Saves2/Components/SelectListsForArtworkModal/SelectListsForArtworkModal" | ||
import { createContext, FC, useContext, useMemo, useState } from "react" | ||
|
||
export interface ManageArtworkForSavesState { | ||
artworkId: string | null | ||
savedListId?: string | ||
isSavedToList: boolean | ||
setArtworkId: (artworkId: string) => void | ||
clearArtworkId: () => void | ||
} | ||
|
||
interface ProviderProps { | ||
savedListId?: string | ||
} | ||
|
||
export const ManageArtworkForSaves = createContext<ManageArtworkForSavesState>( | ||
(null as unknown) as ManageArtworkForSavesState | ||
) | ||
|
||
export const useManageArtworkForSavesContext = () => { | ||
return useContext(ManageArtworkForSaves) | ||
} | ||
|
||
/** | ||
* | ||
* If `savedListId` was passed, it means the user is on a saved artwork list page | ||
* In this case, whether the artwork is saved or not will depend on the local state (not on the status received from backend) | ||
* | ||
* https://artsy.net/collector-profile/saves2 | ||
*/ | ||
export const ManageArtworkForSavesProvider: FC<ProviderProps> = ({ | ||
children, | ||
savedListId, | ||
}) => { | ||
const [artworkEntityId, setArtworkEntityId] = useState<string | null>(null) | ||
const [isSavedToList, setIsSavedToList] = useState(!!savedListId) | ||
|
||
const setArtworkId = (artworkId: string) => { | ||
setArtworkEntityId(artworkId) | ||
} | ||
|
||
const clearArtworkId = () => { | ||
setArtworkEntityId(null) | ||
} | ||
|
||
const value: ManageArtworkForSavesState = useMemo( | ||
() => ({ | ||
artworkId: artworkEntityId, | ||
savedListId, | ||
isSavedToList, | ||
setArtworkId, | ||
clearArtworkId, | ||
}), | ||
[artworkEntityId, savedListId, isSavedToList] | ||
) | ||
|
||
const handleSaveListsForArtwork = (listIds: string[]) => { | ||
if (savedListId) { | ||
setIsSavedToList(listIds.includes(savedListId)) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<ManageArtworkForSaves.Provider value={value}> | ||
{children} | ||
</ManageArtworkForSaves.Provider> | ||
|
||
{!!artworkEntityId && ( | ||
<SelectListsForArtworkModalQueryRender | ||
artworkID={artworkEntityId} | ||
onClose={clearArtworkId} | ||
onSave={handleSaveListsForArtwork} | ||
/> | ||
)} | ||
</> | ||
) | ||
} |
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.