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
LB-1230: Added ability to edit comment after pinning a Listen #2799
base: master
Are you sure you want to change the base?
Conversation
1. New route added: /pin/update/<id> 2. Adjusted frontent code to use the API
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.
Thanks for opening a PR! It's looking quite good !
I did a first round of review without running the code, but it's looking functional already.
Some questions about return value and statuses below:
Hi, thanks for your feedbacks. I will work on them |
@MonkeyDo I have pushed an update. Please have a look when you feel better :) |
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.
Thanks for the modifications, I have a couple more comments but it's looking nice !
Co-authored-by: Monkey Do <MonkeyDo@users.noreply.github.com>
Co-authored-by: Monkey Do <MonkeyDo@users.noreply.github.com>
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.
Thanks for those changes, the code looks great now !
I deployed the PR to our test server, and it's working nicely! I was able to update a comment without any issue, nice work !
Through testing I do have two more pieces of feedback from a user perspective. Sorry about not realizing sooner !
- It would be useful to have the current pin comment in the textarea when I open the modal to edit the pin. Currently to update a typo I would have to copy the comment first. Left some comments about that below
- I would want the UI to update so that the new text content is shown on the pin card on the page. Also left some comments to that effect, but basically we can consider the call
modal.show(
as a promise and make the modal return a value when the API call succeeds (in this case the updated text).
action={() => { | ||
NiceModal.show(PinRecordingModal, { | ||
recordingToPin: listen, | ||
rowId: pinnedRecording.row_id, |
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.
Here we also want to pass pinnedRecording.blurb_content
as a new initialBlurbContent
@@ -14,6 +14,7 @@ import { ToastMsg } from "../notifications/Notifications"; | |||
export type PinRecordingModalProps = { | |||
recordingToPin: Listen; | |||
onSuccessfulPin?: (pinnedrecording: PinnedRecording) => void; | |||
rowId?: number; | |||
}; |
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.
new initialBlurbContent?: string;
prop required here
const modal = useModal(); | ||
const isUpdate = Boolean(rowId); | ||
const [blurbContent, setBlurbContent] = React.useState(""); |
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.
Set initial blurb content here, fallback to the empty string as before:
const [blurbContent, setBlurbContent] = React.useState(""); | |
const [blurbContent, setBlurbContent] = React.useState(initialBlurbContent ?? ""); |
With the other related changes that should mean you have the existing content in the textarea when you open the modal
{ | ||
toastId: "pin-update-success", | ||
} | ||
); |
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.
Here we can have the modal return the updated text so we can update the UI accordingly:
); | |
); | |
modal.resolve(blurbContent); |
I'll leave a comment in PinnedRecordingCard for how to use the returned value.
I don't know if we need to return anything when there is an error, in the catch block below.
NiceModal.show(PinRecordingModal, { | ||
recordingToPin: listen, | ||
rowId: pinnedRecording.row_id, | ||
}); |
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.
There is a good example in the codebase of how to use that return value in the PinnedRecordingCard component:
listenbrainz-server/frontend/js/src/user/playlists/Playlists.tsx
Lines 171 to 175 in c8b5abf
NiceModal.show(CreateOrEditPlaylistModal) | |
// @ts-ignore | |
.then((playlist: JSPFPlaylist) => { | |
this.onPlaylistCreated(playlist); | |
}); |
That also means you will have to store pinnedRecording
in the component state of PinnedRecordingCard rather than using it from the props.
You'll need a new class method updatePinnedRecording
or something like that where you update the state accordingly, similar to what we do here:
listenbrainz-server/frontend/js/src/user/playlists/Playlists.tsx
Lines 96 to 101 in c8b5abf
onPlaylistCreated = async (playlist: JSPFPlaylist): Promise<void> => { | |
const { playlists } = this.state; | |
this.setState({ | |
playlists: [playlist, ...playlists], | |
}); | |
}; |
Except since pinnedRecording is an object we want to merge properties, something like:
this.setState( currentState => ({
pinnedRecording: {
...currentState.pinnedRecording,
blurb_content: updatedBlurbContent},
}));
Actually the current behavior was inlined to what happens when we pin a track. It only shows up in pin when the user refreshes. I have observed this behavior at multiple places in the webapp. That was the reason I tried to keep it inlined to that behavior. |
Yes, I didn't want to muddy the waters by mentioning it, but I did realize the pin is not updated on the page when pinning a track, which is definitely not great UX :) I think since you are working on that feature, and since you noticed it yourself, you will be in a great position to fix that too in your next PR, if you are interested in doing that. |
Hi @lzzy12 ! |
Sorry got caught up with something. Will be finishing it this weekend |
Problem
Fixes this Ticket:
https://tickets.metabrainz.org/browse/LB-1230
Solution
Added an extra action for pinned listen: