Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

lzzy12
Copy link

@lzzy12 lzzy12 commented Feb 27, 2024

Problem

Fixes this Ticket:
https://tickets.metabrainz.org/browse/LB-1230

Solution

Added an extra action for pinned listen:
image

@lzzy12 lzzy12 changed the title Added ability to edit comment after pinning a Listen LB-1230 Added ability to edit comment after pinning a Listen Feb 27, 2024
@lzzy12 lzzy12 changed the title LB-1230 Added ability to edit comment after pinning a Listen LB-1230: Added ability to edit comment after pinning a Listen Feb 27, 2024
1. New route added: /pin/update/<id>
2. Adjusted frontent code to use the API
@pep8speaks
Copy link

pep8speaks commented Feb 27, 2024

Hello @lzzy12! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-03-05 10:23:40 UTC

Copy link
Contributor

@MonkeyDo MonkeyDo left a 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:

frontend/js/src/pins/PinRecordingModal.tsx Outdated Show resolved Hide resolved
frontend/js/src/pins/PinRecordingModal.tsx Outdated Show resolved Hide resolved
frontend/js/src/pins/PinRecordingModal.tsx Outdated Show resolved Hide resolved
frontend/js/src/utils/APIService.ts Show resolved Hide resolved
frontend/js/src/user/components/PinnedRecordingCard.tsx Outdated Show resolved Hide resolved
@lzzy12
Copy link
Author

lzzy12 commented Feb 27, 2024

Hi, thanks for your feedbacks. I will work on them

@lzzy12
Copy link
Author

lzzy12 commented Feb 29, 2024

@MonkeyDo I have pushed an update. Please have a look when you feel better :)

Copy link
Contributor

@MonkeyDo MonkeyDo left a 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 !

frontend/js/src/pins/PinRecordingModal.tsx Outdated Show resolved Hide resolved
frontend/js/src/pins/PinRecordingModal.tsx Outdated Show resolved Hide resolved
frontend/js/src/utils/APIService.ts Show resolved Hide resolved
lzzy12 and others added 2 commits March 4, 2024 22:50
Co-authored-by: Monkey Do <MonkeyDo@users.noreply.github.com>
Co-authored-by: Monkey Do <MonkeyDo@users.noreply.github.com>
Copy link
Contributor

@MonkeyDo MonkeyDo left a 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,
Copy link
Contributor

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;
};
Copy link
Contributor

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("");
Copy link
Contributor

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:

Suggested change
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",
}
);
Copy link
Contributor

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:

Suggested change
);
);
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,
});
Copy link
Contributor

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:

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:

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},
    }));

@lzzy12
Copy link
Author

lzzy12 commented Mar 5, 2024

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.
I will work on it to implement the suggested changes

@MonkeyDo
Copy link
Contributor

MonkeyDo commented Mar 5, 2024

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.
I will work on it to implement the suggested changes

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.

@MonkeyDo
Copy link
Contributor

MonkeyDo commented Apr 3, 2024

Hi @lzzy12 !
Just checking in to see if you have some time to finish this PR, or if you would rather pass the baton to someone else.
Either way is fine by me, please let me know :)

@lzzy12
Copy link
Author

lzzy12 commented Apr 3, 2024

Sorry got caught up with something. Will be finishing it this weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants