-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Solution #889
base: master
Are you sure you want to change the base?
Solution #889
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.
GJ! Keep going! The main point: you should fix app behavior in some cases (read requirements, check tests)
src/components/UserSelector.tsx
Outdated
import { getUsers } from '../api/ApiMethods'; | ||
|
||
type Props = { | ||
setSelectUser: (v: User) => 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.
v
is a bad argument name
src/components/NewCommentForm.tsx
Outdated
className="input is-danger" | ||
className={classNames('input', { 'is-danger': checkEmailName })} | ||
value={formInputs.email} | ||
onChange={(e) => handleChange(e)} |
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.
onChange={(e) => handleChange(e)} | |
onChange={handleChange} |
you don't need wrapper function in such cases
src/components/NewCommentForm.tsx
Outdated
<button type="submit" className="button is-link is-loading"> | ||
<button | ||
type="submit" | ||
onClick={() => setTuched(true)} |
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.
onClick={() => setTuched(true)} | |
onClick={() => setTouched(true)} |
})); | ||
}; | ||
|
||
const handleClear = () => { |
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.
src/App.tsx
Outdated
export const App: React.FC = () => { | ||
const [selectUser, setSelectUser] = useState<User | null>(null); |
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.
const [selectUser, setSelectUser] = useState<User | null>(null); | |
const [selectedUser, setSelectedUser] = useState<User | null>(null); |
src/App.tsx
Outdated
.catch(() => setHasError(true)) | ||
.finally(() => { | ||
setLoading(false); | ||
setHasSelect(true); |
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 may just check selectedUser
variable instead of creating an additional state
src/App.tsx
Outdated
const [hasSelect, setHasSelect] = useState(false); | ||
const [hasError, setHasError] = useState(false); | ||
const [openPost, setOpenPost] = useState<Post | null>(null); | ||
const [openForm, setOpenForm] = useState(false); |
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.
const [openForm, setOpenForm] = useState(false); | |
const [isFormOpen, setIsFormOpen] = useState(false); |
fix everywhere: https://dev.to/michi/tips-on-naming-boolean-variables-cleaner-code-35ig
src/components/PostDetails.tsx
Outdated
</button> | ||
</div> | ||
getComment(openPost.id) | ||
.then(PostComments => setPostComments(PostComments)) |
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.
.then(PostComments => setPostComments(PostComments)) | |
.then(costComments => setPostComments(costComments)) |
camelCase for variable names (that's not a class, React component or type, etc)
src/components/PostDetails.tsx
Outdated
) : ( | ||
<> | ||
<p className="title is-4">Comments:</p> | ||
{postComments.map((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.
{postComments.map((com) => ( | |
{postComments.map((comment) => ( |
do not use short forms for variable names
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.
src/components/NewCommentForm.tsx
Outdated
body: '', | ||
}); | ||
const [loading, setLoading] = useState(false); | ||
const [tuched, setTouched] = useState(false); |
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.
const [tuched, setTouched] = useState(false); | |
const [touched, setTouched] = useState(false); |
src/App.tsx
Outdated
setHasError(false); | ||
|
||
getPosts(selectedUser.id) | ||
.then(posts => setUserPosts(posts)) |
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.
.then(posts => setUserPosts(posts)) | |
.then(setUserPosts) |
we can simplify this logic
src/components/PostDetails.tsx
Outdated
import { NewCommentForm } from './NewCommentForm'; | ||
|
||
export const PostDetails: React.FC = () => { | ||
type Props = { | ||
isPostOpen: Post | null, |
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.
isPostOpen: Post | null, | |
openedPost: Post | null, |
we usually name var with is
if it's 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.
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 strange with the name field
Screen.Recording.2023-08-21.at.21.21.22.mov
src/components/UserSelector.tsx
Outdated
> | ||
<span>Choose a user</span> | ||
<span>{selectedUser ? selectedUser.name : 'Choose a user'}</span> |
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.
<span>{selectedUser ? selectedUser.name : 'Choose a user'}</span> | |
<span>{selectedUser?.name || 'Choose a user'}</span> |
src/components/UserSelector.tsx
Outdated
}; | ||
|
||
useEffect(() => { | ||
getUsers().then(users => setAllUsers(users)); |
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.
getUsers().then(users => setAllUsers(users)); | |
getUsers().then(setAllUsers); |
we can simplify it
src/components/UserSelector.tsx
Outdated
selectedUser, | ||
setOpenedPost, | ||
}) => { | ||
const [allUsers, setAllUsers] = useState<null | User[]>(null); |
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.
const [allUsers, setAllUsers] = useState<null | User[]>(null); | |
const [allUsers, setAllUsers] = useState<User[]>([]); |
we can just use it as empty array instead of the null
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
DEMO