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

Solution #889

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

Solution #889

wants to merge 6 commits into from

Conversation

Ssviatt
Copy link

@Ssviatt Ssviatt commented Aug 11, 2023

Copy link

@TarasHoliuk TarasHoliuk left a 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 Show resolved Hide resolved
import { getUsers } from '../api/ApiMethods';

type Props = {
setSelectUser: (v: User) => void,

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

className="input is-danger"
className={classNames('input', { 'is-danger': checkEmailName })}
value={formInputs.email}
onChange={(e) => handleChange(e)}

Choose a reason for hiding this comment

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

Suggested change
onChange={(e) => handleChange(e)}
onChange={handleChange}

you don't need wrapper function in such cases

<button type="submit" className="button is-link is-loading">
<button
type="submit"
onClick={() => setTuched(true)}

Choose a reason for hiding this comment

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

Suggested change
onClick={() => setTuched(true)}
onClick={() => setTouched(true)}

}));
};

const handleClear = () => {

Choose a reason for hiding this comment

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

you should also clear errors (one of tests fails because of this):
image

src/App.tsx Outdated
export const App: React.FC = () => {
const [selectUser, setSelectUser] = useState<User | null>(null);

Choose a reason for hiding this comment

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

Suggested change
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);

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

Choose a reason for hiding this comment

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

Suggested change
const [openForm, setOpenForm] = useState(false);
const [isFormOpen, setIsFormOpen] = useState(false);

fix everywhere: https://dev.to/michi/tips-on-naming-boolean-variables-cleaner-code-35ig

</button>
</div>
getComment(openPost.id)
.then(PostComments => setPostComments(PostComments))

Choose a reason for hiding this comment

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

Suggested change
.then(PostComments => setPostComments(PostComments))
.then(costComments => setPostComments(costComments))

camelCase for variable names (that's not a class, React component or type, etc)

) : (
<>
<p className="title is-4">Comments:</p>
{postComments.map((com) => (

Choose a reason for hiding this comment

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

Suggested change
{postComments.map((com) => (
{postComments.map((comment) => (

do not use short forms for variable names

Copy link

@DarkMistyRoom DarkMistyRoom left a comment

Choose a reason for hiding this comment

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

fix these tests, please
image
image
image

body: '',
});
const [loading, setLoading] = useState(false);
const [tuched, setTouched] = useState(false);

Choose a reason for hiding this comment

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

Suggested change
const [tuched, setTouched] = useState(false);
const [touched, setTouched] = useState(false);

src/components/PostDetails.tsx Outdated Show resolved Hide resolved
src/App.tsx Outdated
setHasError(false);

getPosts(selectedUser.id)
.then(posts => setUserPosts(posts))

Choose a reason for hiding this comment

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

Suggested change
.then(posts => setUserPosts(posts))
.then(setUserPosts)

we can simplify this logic

import { NewCommentForm } from './NewCommentForm';

export const PostDetails: React.FC = () => {
type Props = {
isPostOpen: Post | null,

Choose a reason for hiding this comment

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

Suggested change
isPostOpen: Post | null,
openedPost: Post | null,

we usually name var with is if it's boolean

Choose a reason for hiding this comment

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

how can it be null if we check if this prop exists
image

Copy link

@etojeDenys etojeDenys left a 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

>
<span>Choose a user</span>
<span>{selectedUser ? selectedUser.name : 'Choose a user'}</span>

Choose a reason for hiding this comment

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

Suggested change
<span>{selectedUser ? selectedUser.name : 'Choose a user'}</span>
<span>{selectedUser?.name || 'Choose a user'}</span>

};

useEffect(() => {
getUsers().then(users => setAllUsers(users));

Choose a reason for hiding this comment

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

Suggested change
getUsers().then(users => setAllUsers(users));
getUsers().then(setAllUsers);

we can simplify it

selectedUser,
setOpenedPost,
}) => {
const [allUsers, setAllUsers] = useState<null | User[]>(null);

Choose a reason for hiding this comment

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

Suggested change
const [allUsers, setAllUsers] = useState<null | User[]>(null);
const [allUsers, setAllUsers] = useState<User[]>([]);

we can just use it as empty array instead of the null

Copy link

@etojeDenys etojeDenys left a comment

Choose a reason for hiding this comment

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

lgtm

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.

4 participants