-
Notifications
You must be signed in to change notification settings - Fork 30
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
QuickTalk: Refactor to functional component #3213
Conversation
@@ -174,21 +148,21 @@ class QuickTalkContainer extends React.Component { | |||
|
|||
const authorization = await getBearerToken(authClient) // Check bearer token to ensure session hasn't timed out |
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.
I think I’ve pointed this bug out before but this will return an empty string if you call it before you call checkCurrent
. See #2986.
@@ -198,11 +172,10 @@ class QuickTalkContainer extends React.Component { | |||
} | |||
|
|||
await talkClient.type('comments').create(comment).save() |
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 could use panoptes.post
to post comments with the new API client.
author_ids = author_ids.filter((id, i) => author_ids.indexOf(id) === i) | ||
|
||
apiClient.type('users').get({ id: author_ids }) |
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 should use panoptes.get
in the new API client.
}) | ||
|
||
talkClient.type('roles') |
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.
Are Talk roles different from Panoptes roles? You can use the new client to get roles. The useProjectRoles
hook has an example.
@@ -101,24 +86,24 @@ class QuickTalkContainer extends React.Component { | |||
page: 1, | |||
sort: 'created_at', // PFE used '-created_at' to sort in reverse order, and I have no idea why. | |||
} | |||
|
|||
|
|||
talkClient.type('comments').get(query) |
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.
The new API client could be used here too.
de64631
to
41649bf
Compare
There’s an auth bug in the existing code, which can be fixed here. All the API calls should use the new |
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.
Looks good but:
- there's an auth bug which blocks the first posted comment from being posted.
- all API requests should really be handled with
panoptes-js
not the old client. - after I post a comment, keyboard focus goes back to the window, or parent document. I'm not sure. Either way, posting a comment from the keyboard works until after the comment is posted, at which point the Quick Talk panel loses keyboard focus.
This might be useful for managing keyboard focus. |
@@ -174,21 +148,21 @@ class QuickTalkContainer extends React.Component { | |||
|
|||
const authorization = await getBearerToken(authClient) // Check bearer token to ensure session hasn't timed out | |||
const user = await authClient.checkCurrent() |
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.
Another thought about auth: Panoptes user sessions are quite long-lived, so call this once, when the component mounts, in order to establish a session (if one exists.)
Then get a bearer token as and when you need access to perform a restricted action, like posting a comment.
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.
You can also use the usePanoptesUser
and usePanoptesAuth
hooks, although that would then limit you to following the Rules of Hooks eg. no conditional execution.
https://github.com/zooniverse/front-end-monorepo/tree/master/packages/lib-classifier/src/hooks#usepanoptesauth
41649bf
to
c7dec75
Compare
Thanks Jim! 👍 I'm merging this PR, with the following goals for the follow up PR:
|
This is the auth bug. |
PR Overview
Package:
lib-classifier
Affects: experimental QuickTalk feature (only affects projects with experimental tool enabled)
This PR refactors the QuickTalkContainer into a functional component.
Testing
lib-classifier
(not app-project) with a project with QuickTalk enabled, e.g. https://local.zooniverse.org:8080/?env=staging&project=darkeshard%2Ftest-project-2022&workflow=3581Known UI issues: (collapsed) QuickTalk button should have a background so it doesn't blend into the page (z-index madness) ; a message saying "you should be logged in if you want to post a message" should appear on the expanded panel.
Status
Ready for review! 👍