Skip to content

Commit

Permalink
Merge pull request #24 from GuiMoraesDev/style/fixTheWayTHowPostAreShown
Browse files Browse the repository at this point in the history
style: fix the way how posts are shown
  • Loading branch information
GuiMoraesDev authored Sep 2, 2022
2 parents ddc5d0a + 76e2d20 commit 9bc356c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 55 deletions.
8 changes: 5 additions & 3 deletions src/layouts/Private/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const Container = styled.div`
height: 100vh;
width: 100vw;
overflow: hidden;
`;

export const Header = styled.header`
Expand Down Expand Up @@ -39,15 +41,15 @@ export const PrivateContent = styled.main`
flex-direction: column;
align-items: center;
justify-content: center;
padding: ${({ theme }) => theme.sizes.dimensions.spacing.xl};
gap: ${({ theme }) => theme.sizes.dimensions.spacing.xl};
width: 100%;
max-width: 600px;
height: 100%;
margin: auto;
overflow-y: auto;
`;
2 changes: 1 addition & 1 deletion src/services/posts.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface GetPostsParams {
}

export interface AllPostsProps extends Post {
Users: {
users: {
id: UserProps['id'];
first_name: UserProps['first_name'];
last_name: UserProps['last_name'];
Expand Down
17 changes: 0 additions & 17 deletions src/styles/global/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
import { createGlobalStyle } from "styled-components";

export default createGlobalStyle`
::-webkit-scrollbar {
width: ${({ theme }) => theme.sizes.common.x2};
height: ${({ theme }) => theme.sizes.common.x2};
}
::-webkit-scrollbar-track {
background-color: ${({ theme }) => theme.themeColors.canvasInverted};
border: ${({ theme }) => theme.borders.solid};
}
::-webkit-scrollbar-thumb {
background-color: ${({ theme }) => theme.themeColors.canvasDark};
border-radius: ${({ theme }) => theme.rounded.full};
}
* {
margin: 0;
padding: 0;
Expand Down
41 changes: 29 additions & 12 deletions src/views/Home/__snapshots__/tests.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,13 @@ exports[`Home page should render correctly 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
padding: 2.0rem;
gap: 2.0rem;
width: 100%;
max-width: 600px;
height: 100%;
margin: auto;
overflow-y: auto;
}
.c1 {
Expand Down Expand Up @@ -198,8 +192,25 @@ exports[`Home page should render correctly 1`] = `
display: grid;
grid-template-columns: 1fr;
width: 100%;
height: 100%;
gap: 1.4rem;
margin-bottom: auto;
}
.c10 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
height: 100%;
width: 100%;
}
<main
Expand All @@ -222,14 +233,14 @@ exports[`Home page should render correctly 1`] = `
class="c5"
data-testid="post-body-input"
id="post-body-input"
maxlength="1000"
maxlength="144"
name="body"
placeholder="What’s happening?"
/>
<p
class="c6"
>
0 / 1000
0 / 144
</p>
<span
class="c7"
Expand Down Expand Up @@ -323,6 +334,12 @@ exports[`Home page should render correctly 1`] = `
</div>
<div
class="c9"
/>
>
<div
class="c10"
>
You have no posts yet
</div>
</div>
</main>
`;
45 changes: 26 additions & 19 deletions src/views/Home/template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { PrivateContent } from 'layouts/Private/styles';

import { AllPostsProps } from 'services/posts.api';

import { POST_MESSAGE_LENGTH } from 'constant';

import * as Styles from './styles';
import { homeResolver, HomeResolverProps } from './validations';

Expand Down Expand Up @@ -45,6 +47,7 @@ const HomeTemplate = ({
error={homeMethods.formState.errors.body?.message}
fullWidth
{...homeMethods.register('body')}
maxLength={POST_MESSAGE_LENGTH}
/>
</Styles.PostsForm>

Expand All @@ -59,27 +62,31 @@ const HomeTemplate = ({
</Styles.PostsFormWrapper>

<Styles.PostsWrapper>
{postsData.map((post) => (
<Styles.Post key={post.id}>
<Styles.AvatarWrapper>
<Avatar
src={post.Users.avatar_url || ''}
alt={post.Users.first_name}
/>
</Styles.AvatarWrapper>
{Boolean(postsData.length) ? (
postsData.map((post) => (
<Styles.Post key={post.id}>
<Styles.AvatarWrapper>
<Avatar
src={post.users.avatar_url || ''}
alt={post.users.first_name}
/>
</Styles.AvatarWrapper>

<Styles.AuthorMetadata>
<Text
label={`${post.Users.first_name} ${post.Users.last_name}`}
isBold
/>
</Styles.AuthorMetadata>
<Styles.AuthorMetadata>
<Text
label={`${post.users.first_name} ${post.users.last_name}`}
isBold
/>
</Styles.AuthorMetadata>

<Styles.PostMessage>
<Text label={post.body} />
</Styles.PostMessage>
</Styles.Post>
))}
<Styles.PostMessage>
<Text label={post.body} />
</Styles.PostMessage>
</Styles.Post>
))
) : (
<Styles.Empty>You have no posts yet</Styles.Empty>
)}
</Styles.PostsWrapper>
</PrivateContent>
);
Expand Down
17 changes: 14 additions & 3 deletions src/views/Home/template/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ export const PostsWrapper = styled.div`
grid-template-columns: 1fr;
width: 100%;
height: 100%;
gap: ${({ theme }) => theme.sizes.dimensions.spacing.md};
margin-bottom: auto;
`;

export const Post = styled.div`
display: grid;
grid-template-columns: 6rem auto;
grid-template-rows: 6rem auto;
grid-template-rows: 2rem auto;
grid-template-areas:
'Avatar AuthorMetadata'
Expand All @@ -44,7 +45,7 @@ export const Post = styled.div`
border: ${({ theme }) => theme.borders.solid};
border-radius: ${({ theme }) => theme.rounded.sm};
padding: ${({ theme }) => theme.sizes.dimensions.spacing.xs};
padding: ${({ theme }) => theme.sizes.dimensions.spacing.sm};
`;

export const AvatarWrapper = styled.div`
Expand All @@ -63,3 +64,13 @@ export const AuthorMetadata = styled.section`
export const PostMessage = styled.section`
grid-area: PostMessage;
`;

export const Empty = styled.div`
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
`;

1 comment on commit 9bc356c

@vercel
Copy link

@vercel vercel bot commented on 9bc356c Sep 2, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

teller – ./

teller-guimoraes.vercel.app
teller-git-main-guimoraes.vercel.app
teller-six.vercel.app

Please sign in to comment.