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

Develop #1175

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

Develop #1175

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@
.message-body {
white-space: pre-line;
}

.tile.is-ancestor {
display: flex;
}

.tile.is-parent {
flex: 1;
padding: 0.75rem;
}
85 changes: 46 additions & 39 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,61 @@ import './App.scss';
import { PostsList } from './components/PostsList';
import { PostDetails } from './components/PostDetails';
import { UserSelector } from './components/UserSelector';
import { Loader } from './components/Loader';
import { useState } from 'react';
import { User } from './types/User';
import { Post } from './types/Post';

export const App = () => (
<main className="section">
<div className="container">
<div className="tile is-ancestor">
<div className="tile is-parent">
<div className="tile is-child box is-success">
<div className="block">
<UserSelector />
</div>

<div className="block" data-cy="MainContent">
<p data-cy="NoSelectedUser">No user selected</p>
export const App = () => {
const [selectedUser, setSelectedUser] = useState<User | null>(null);
const [selectedPost, setSelectedPost] = useState<Post | null>(null);

<Loader />
const handleUserSelect = (user: User) => {
setSelectedUser(user);
setSelectedPost(null);
};

<div
className="notification is-danger"
data-cy="PostsLoadingError"
>
Something went wrong!
return (
<main className="section">
<div className="container">
<div className="tile is-ancestor">
<div className="tile is-parent">
<div className="tile is-child box is-success">
<div className="block">
<UserSelector
selectedUser={selectedUser}
onSelectUser={handleUserSelect}
/>
</div>

<div className="notification is-warning" data-cy="NoPostsYet">
No posts yet
<div className="block" data-cy="MainContent">
{selectedUser ? (
<PostsList
selectedUser={selectedUser}
onPostSelect={setSelectedPost}
/>
) : (
<p data-cy="NoSelectedUser">No user selected</p>
)}
</div>

<PostsList />
</div>
</div>
</div>

<div
data-cy="Sidebar"
className={classNames(
'tile',
'is-parent',
'is-8-desktop',
'Sidebar',
'Sidebar--open',
)}
>
<div className="tile is-child box is-success ">
<PostDetails />
<div
data-cy="Sidebar"
className={classNames(
'tile',
'is-parent',
'is-8-desktop',
'Sidebar',
{ 'Sidebar--open': selectedPost },
)}
>
<div className="tile is-child box is-success ">
{selectedPost && <PostDetails post={selectedPost} />}
</div>
</div>
</div>
</div>
</div>
</main>
);
</main>
);
};
18 changes: 18 additions & 0 deletions src/api/comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ApiPath } from '../enums/api-path.enum';
import { QueryParams } from '../enums/query-params.enum';
import { Comment } from '../types/Comment';
import { client } from '../utils/fetchClient';

export const getCommentsByPost = (postId: number) => {
return client.get<Comment[]>(
`${ApiPath.COMMENTS}?${QueryParams.POST_ID}=${postId}`,
);
};

export const addComment = (comment: Omit<Comment, 'id'>) => {
return client.post<Comment>(ApiPath.COMMENTS, comment);
};

export const deleteComment = (commentId: number) => {
return client.delete(`${ApiPath.COMMENTS}/${commentId}`);
};
9 changes: 9 additions & 0 deletions src/api/posts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { client } from '../utils/fetchClient';
import { Post } from '../types/Post';
import { ApiPath, QueryParams } from '../enums/enums';

export const getPostsByUserId = (userId: number) => {
return client.get<Post[]>(
`${ApiPath.POSTS}?${QueryParams.USER_ID}=${userId}`,
);
};
5 changes: 5 additions & 0 deletions src/api/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { User } from '../types/User';
import { client } from '../utils/fetchClient';
import { ApiPath } from '../enums/api-path.enum';

export const getUsers = () => client.get<User[]>(ApiPath.USERS);
Loading
Loading