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

[#8467] Allow moderators to like #5751

Merged
merged 1 commit into from
Nov 20, 2024
Merged

Conversation

sevfurneaux
Copy link
Collaborator

@sevfurneaux sevfurneaux commented Nov 19, 2024

Describe your changes
This PR refactors the QuestionModerator component to a functional component, and also allows moderators to like alongside other users.

Tasks

  • PR name contains story or task reference
  • Steps to recreate and test the changes
  • Documentation (docs and inline)
  • Tests (including n+1 and django_assert_num_queries where applicable)
  • Changelog

@sevfurneaux sevfurneaux self-assigned this Nov 19, 2024
@sevfurneaux sevfurneaux force-pushed the sf-2024-allow-moderators-to-like branch from 3cfc4a4 to 61ef9bf Compare November 19, 2024 12:17
Copy link
Collaborator

@vellip vellip 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 converting & updating this part too. Good job! I just got a few things.

Comment on lines 22 to 36
useEffect(() => {
setisOnShortlist(props.is_on_shortlist)
}, [props.is_on_shortlist])

useEffect(() => {
setIsLive(props.is_live)
}, [props.is_live])

useEffect(() => {
setIsHidden(props.is_hidden)
}, [props.is_hidden])

useEffect(() => {
setIsAnswered(props.is_answered)
}, [props.is_answered])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing it this way instead of using a callback provided by the parent component? If you need to update your props, you should use a callback and not copy props into state.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, you just converted the old code. Could you investigate it still? Only if it doesn't take much time. The live-questions aren't really used that much.

Copy link
Collaborator Author

@sevfurneaux sevfurneaux Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing it this way instead of using a callback provided by the parent component?

@vellip I asked myself the same question of the original implementation, so I used all the props directly, without copying state. However doing this means on update of moderator buttons in this component, their interaction is delayed to the 500 ms polling when the parent props are updated. TLDR: the copied local state makes this faster.

If we can think of an alternative approach, happy to change it!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, then let's leave it in. Maybe you can add a small comment with your findings or link to this discussion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_answered: this.props.is_answered
}
}
const QuestionModerator = (props) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe destructure the props argument

Copy link
Collaborator Author

@sevfurneaux sevfurneaux Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vellip Destructuring to this:

const QuestionModerator = ({
  category,
  children,
  displayIsAnswered,
  displayIsHidden,
  displayIsLive,
  displayIsOnShortlist,
  handleLike,
  id,
  is_answered,
  is_hidden,
  is_live,
  is_on_shortlist,
  likes,
  removeFromList,
  togglePollingPaused,
  updateQuestion
}) => {

Causes eslint errors:

error Identifier 'is_answered' is not in camel case

But changing to isAnswered then conflicts with the isAnswered local state naming:

const [isAnswered, setIsAnswered] = useState(is_answered)

Let's keep as props for now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const QuestionModerator = ({
  category,
  children,
  displayIsAnswered,
  displayIsHidden,
  displayIsLive,
  displayIsOnShortlist,
  handleLike,
  id,
  **is_answered: _isAnswered,**
  is_hidden,
  is_live,
  is_on_shortlist,
  likes,
  removeFromList,
  togglePollingPaused,
  updateQuestion
}) => {

does that work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the ** of course

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<button
type="button"
className={classNames(
'cardbutton card__button card__button--live',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check if cardbutton is still needed? I didnt find any styling for it. It also doesn't look very BEM to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cardbutton is from the compiled berlin_css.css which is part of the Card HTML in the styleguide: https://styleguide.berlin.de/patterns/09-vertical_marketing-page-modul-card/09-vertical_marketing-page-modul-card.html

@sevfurneaux sevfurneaux force-pushed the sf-2024-allow-moderators-to-like branch from 61ef9bf to c7ad71f Compare November 20, 2024 09:49
@vellip vellip merged commit 56f37ff into dev Nov 20, 2024
3 checks passed
@vellip vellip deleted the sf-2024-allow-moderators-to-like branch November 20, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants