Skip to content

Commit

Permalink
feat(new component): cria o componente gituserrepos
Browse files Browse the repository at this point in the history
cria o componente gituserrespos populado com os dados obtidos pela api do github

issue #13
  • Loading branch information
leottx committed Jan 7, 2022
1 parent 6e3faa8 commit a4fd288
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 5 deletions.
121 changes: 116 additions & 5 deletions src/assets/styles/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const SearchButton = styled.button`
color: var(--white);
font-weight: 700;
margin-left: auto;
transition-property: 'background';
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
&:hover {
Expand All @@ -61,16 +61,18 @@ export const Wrapper = styled.div`

export const UserContainer = styled.article`
display: grid;
box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1),
0 8px 10px -6px rgb(0 0 0 / 0.1);
box-shadow: 0 20px 25px -5px rgba(38, 108, 255, 0.1),
0 8px 10px -6px rgba(38, 108, 255, 0.1);
grid-template-columns: 1fr 2fr;
gap: 2.4rem;
background: var(--white);
padding: 3.6rem 2.4rem;
border-radius: 1.5rem;
margin-bottom: 3.6rem;
@media screen and (min-width: 768px) {
padding: 3.6rem;
gap: 3.2rem;
margin-bottom: 4.2rem;
}
`;

Expand Down Expand Up @@ -225,7 +227,7 @@ export const UserBoardFooter = styled.footer`

export const UserLinkList = styled.ul`
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 2rem;
margin-bottom: 2rem;
`;
Expand All @@ -246,7 +248,8 @@ export const UserFooterItem = styled.li`
gap: 1rem;
max-width: 100%;
span {
width: 220px;
width: auto;
max-width: 180px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
Expand All @@ -257,9 +260,117 @@ export const UserFooterItem = styled.li`
}
@media screen and (min-width: 667px) {
font-size: 1.6rem;
span {
max-width: 230px;
}
svg {
width: 26px;
height: 26px;
}
}
`;

export const RepoContainer = styled.section``;

export const RepoButton = styled.button`
border-radius: 1rem;
border: 2px solid var(--txt-5);
padding: 0.8em 1em;
color: var(--txt-5);
font-weight: 700;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
font-size: 1.4rem;
display: block;
margin: 0 auto;
&:hover {
color: var(--white);
background: ${({ theme: { c } }) => c.bgBtn};
}
@media screen and (min-width: 667px) {
font-size: 1.6rem;
}
`;

export const RepoCardsList = styled.ul`
display: flex;
flex-direction: column;
gap: 2.4rem;
@media screen and (min-width: 768px) {
font-size: 1.6rem;
gap: 3rem;
}
`;

export const RepoCard = styled.li`
border-radius: 1.5rem;
background: var(--white);
padding: 2rem;
font-size: 1.4rem;
color: var(--txt-2);
line-height: 1.6;
box-shadow: 0 20px 25px -5px rgba(38, 108, 255, 0.1),
0 8px 10px -6px rgba(38, 108, 255, 0.1);
@media screen and (min-width: 667px) {
font-size: 1.6rem;
}
`;

export const RepoTitle = styled.h3`
font-size: 1.8rem;
margin-bottom: 0.5rem;
font-weight: 700;
color: var(--txt-1);
display: inline-flex;
align-items: center;
gap: 0.6rem;
cursor: pointer;
&:hover {
color: var(--txt-3);
}
&:hover a {
text-decoration: underline;
}
svg {
width: 18px;
height: auto;
transform: rotate(-53deg);
}
@media screen and (min-width: 667px) {
font-size: 2rem;
}
`;

export const RepoLink = styled.a`
color: inherit;
width: auto;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 200px;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
@media screen and (min-width: 667px) {
max-width: 550px;
}
`;

export const RepoText = styled.p`
margin-bottom: 1.2rem;
max-width: 550px;
`;

export const RepoWrapper = styled.div`
display: flex;
align-items: center;
gap: 1rem;
flex-wrap: wrap;
`;

export const RepoExtra = styled.span`
svg {
margin-right: 0.5rem;
}
`;
10 changes: 10 additions & 0 deletions src/components/GitMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@ import { Main } from '@Styles/main';
// COMPONENTS
import GitSearch from '@Components/GitSearch';
import GitUserBoard from '@Components/GitUserBoard';
import GitUserRepos from '@Components/GitUserRepos';

// UTILS
import { getUserData } from '@Utils/api';

const GitMain = () => {
const [userData, setUserData] = useState(null);
const [showRepos, setShowRepos] = useState(false);

const buildUserProfile = (username) => {
getUserData(username).then((data) => {
setUserData(data);
setShowRepos(false);
});
};

return (
<Main>
<GitSearch buildUserProfile={buildUserProfile} />
{userData && <GitUserBoard userProfile={userData.profile} />}
{userData && (
<GitUserRepos
reposList={userData.repos}
showRepos={showRepos}
setShowRepos={setShowRepos}
/>
)}
</Main>
);
};
Expand Down
79 changes: 79 additions & 0 deletions src/components/GitUserRepos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { useState } from 'react';
import { ThemeProvider } from 'styled-components';

// THEME
import theme from '@Styles/theme';

// ICONS
import { FaRegStar, FaStar } from 'react-icons/fa';
import { GoPrimitiveDot } from 'react-icons/go';
import { FaRegHandPointer } from 'react-icons/fa';

// STYLES
import {
RepoContainer,
RepoButton,
RepoText,
RepoCardsList,
RepoCard,
RepoTitle,
RepoLink,
RepoWrapper,
RepoExtra,
} from '@Styles/main';

// UTILS
import { nanoid } from 'nanoid';
import { formatDate } from '@Utils/api';

const GitUserRepos = ({ reposList, showRepos, setShowRepos }) => {
const handleShowRepos = () => {
setShowRepos(!showRepos);
};

return (
<RepoContainer>
<ThemeProvider theme={theme}>
{!showRepos && (
<RepoButton onClick={() => handleShowRepos()}>Show Repos</RepoButton>
)}
</ThemeProvider>
{showRepos && (
<RepoCardsList>
{reposList.map((repo) => {
const {
html_url,
name,
description,
stargazers_count,
updated_at,
} = repo;
return (
<RepoCard key={`repo-${nanoid()}`}>
<RepoTitle>
<RepoLink href={html_url} target='_blank'>
{name}
</RepoLink>
<FaRegHandPointer />
</RepoTitle>
<RepoText>
{description ? description : 'No description'}
</RepoText>
<RepoWrapper>
<RepoExtra>
<FaRegStar />
{stargazers_count}
</RepoExtra>
<GoPrimitiveDot size={10} />
<RepoExtra>Updated at {formatDate(updated_at)}</RepoExtra>
</RepoWrapper>
</RepoCard>
);
})}
</RepoCardsList>
)}
</RepoContainer>
);
};

export default GitUserRepos;

0 comments on commit a4fd288

Please sign in to comment.