-
Notifications
You must be signed in to change notification settings - Fork 5
My Saved Decks #2117
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
base: main
Are you sure you want to change the base?
My Saved Decks #2117
Changes from all commits
6f4f250
4177461
c14bc5a
167d888
dde2c73
7d7aec7
7f85984
5387fc2
0c53946
18b1fcf
4d4d4d7
9d6cd42
1711da5
7cc9891
d427884
0653504
30c302e
9e636be
b1528f2
1e31038
c8937d1
88d35da
338f9bd
0c743b7
90cb196
fd52424
df61a78
6f88d73
ff43104
616dcda
0a4b7a2
160ebcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import React, { useCallback, useMemo, useState } from "react"; | ||
| import { IconButton } from "./AffixButton"; | ||
| import { GameboardDTO } from "../../../IsaacApiTypes"; | ||
| import classNames from "classnames"; | ||
| import { ButtonProps } from "reactstrap"; | ||
| import { saveGameboard, selectors, unlinkUserFromGameboard, useAppDispatch, useAppSelector } from "../../state"; | ||
| import { isLoggedIn, siteSpecific } from "../../services"; | ||
|
|
||
| interface SaveBoardButtonProps extends ButtonProps { | ||
| board: GameboardDTO; | ||
| size?: "sm" | "md"; // "md" default (as used for PageMetadata buttons); "sm" aligns with regular .btn padding | ||
| } | ||
|
|
||
| export const SaveBoardButton = (props: SaveBoardButtonProps) => { | ||
| const { board, size, className, ...rest } = props; | ||
|
|
||
| const dispatch = useAppDispatch(); | ||
| const user = useAppSelector(selectors.user.loggedInOrNull); | ||
|
|
||
| const [justLinked, setJustLinked] = useState(false); | ||
| const isLinked = useMemo(() => board.savedToCurrentUser || justLinked, [board, justLinked]); | ||
|
|
||
| const linkBoard = useCallback(() => { | ||
| if (!user || !board) return; | ||
| setJustLinked(true); | ||
| void dispatch(saveGameboard({ | ||
| boardId: board.id ?? "", | ||
| boardTitle: board.title, | ||
| user, | ||
| })); | ||
| }, [user, board, dispatch]); | ||
|
|
||
| const unlinkBoard = useCallback(() => { | ||
| if (!user || !board) return; | ||
| const confirmMessage = board.ownerUserId === user.id && !board.tags?.includes("ISAAC_BOARD") | ||
| ? `Are you sure you want to unsave your board '${board.title}' from your account? You'll only be able to find it again if you've set it as an assignment.` | ||
| : `Are you sure you want to unsave '${board.title}' from your account?`; | ||
| if (confirm(confirmMessage)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has strange interactions with the existing deck deletion code at https://github.com/isaacphysics/isaac-react-app/blob/main/src/app/state/slices/api/gameboards.ts#L162.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with your last point; to me, the spirit of these changes are to make saving a completely separate interaction to creating, assigning, etc. You should be free to unsave a deck if you're done with it, regardless of whether it is assigned, so long as it is still accessible from somewhere. Right now, this last point is not met, since I have not yet done the changes to Set Assignments; but when that shows all assigned decks, this should work as expected. I've removed the whole chunk of code around stopping this; it's obviously a little weird right now with not being able to access assigned ones, but this should be resolved soon. |
||
| setJustLinked(false); | ||
| void dispatch(unlinkUserFromGameboard({ | ||
| boardId: board.id ?? "", | ||
| boardTitle: board.title | ||
| })); | ||
| } | ||
| }, [user, board, dispatch]); | ||
|
|
||
| if (!isLoggedIn(user)) return null; // anon users should not be able to save boards | ||
|
|
||
| return <IconButton | ||
| icon={{ | ||
| name: classNames("icon-star", siteSpecific("icon-color-black-hoverable", undefined), { "fill": isLinked, "anim-star-select": justLinked }), | ||
| color: siteSpecific(undefined, props.color === "solid" ? "white" : "primary") | ||
| }} | ||
| className={classNames(className, "w-max-content h-max-content action-button", {"icon-button-sm": size === "sm"})} | ||
| title={isLinked ? "Unsave board" : "Save board"} | ||
| onClick={(e) => { | ||
| e.preventDefault(); | ||
| if (isLinked) { | ||
| unlinkBoard(); | ||
| } else { | ||
| linkBoard(); | ||
| } | ||
| }} | ||
| {...rest} | ||
| />; | ||
| }; | ||
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.
This seems to be an API issue, but I'll leave a comment here while it's on my mind and it can be worked on later like the other known issues. This
board.savedToCurrentUseris not behaving as it should for gameboard pages themselves. The board appears as saved if and only if the user has attempted any questions on it (as would've previously created a link).Using the button does successfully save/unsave boards if in the right state to do so, but that state does not reflect the actual saved-ness of the board and whether it shows up in "My saved decks".
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.
Ah, thanks for spotting this. There's a card for
savedToCurrentUsernot working for My Assignments and book pages, but this seems to be a third case.