-
Notifications
You must be signed in to change notification settings - Fork 56
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
Issue 1542/refactor tags hook #1558
Issue 1542/refactor tags hook #1558
Conversation
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.
Nice fix! This lgtm but I would like @richardolsson to double check, as we are getting familiar with this new pattern :)
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.
Nice work in general! There are some changes that I think would make the code cleaner though. I've commented below.
src/features/tags/hooks/useTag.ts
Outdated
tagData: ZetkinTag | null; | ||
tagError: unknown | null; | ||
tagIsLoading: boolean; |
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 name of the hook already tells us that the hook will return a tag, so there is no need for these prefixes. I would call these properties:
tagData: ZetkinTag | null; | |
tagError: unknown | null; | |
tagIsLoading: boolean; | |
data: ZetkinTag | null; | |
error: unknown | null; | |
isLoading: boolean; |
src/features/tags/hooks/useTag.ts
Outdated
); | ||
store.dispatch(tagAssigned([personId, tag])); | ||
}; | ||
const getTag = () => { |
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 function is unnecessary. Inline it's contents inside the hook instead. You can just grab the return value from loadItemIfNecessary
and use that further down the function where you are currently calling getTag()
.
src/features/tags/hooks/useTag.ts
Outdated
assignToPerson: (personId: number, value?: string) => void; | ||
removeFromPerson: (personId: number) => Promise<void>; |
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 like how these mutation functions are returned.
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.
lgtm 🚀
fcf7956
into
issue-1542/refactor-to-use-hooks
Description
This PR refactors the
tagModel
intouseTag
hook.Screenshots
Changes
useTag
and fix its relevant codesuseTagMutation
and fix its relevant codestagModel.ts
Notes to reviewer
Didn't delete
tagRepo
sinceassignTagToPerson
andremoveTagFromPerson
are used inViewDataModel.ts
Because I noticed that
assignTagToPerson
andremoveTagFromPerson
are used in other places, I decided to make auseTagMutation
hook instead of put those methods inuseTag
.This will be useful in the future, once
tagRepo
is removed, as you'll be able to useuseTagMutation
to other hooks.Related issues
part of issue-1542