Skip to content
Open
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
27 changes: 25 additions & 2 deletions src/pages/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import api from '../../services/api';
import logoImage from '../../assets/logo.svg';
import loadingImage from '../../assets/loading.svg';

import { Title, Form, Badges, Error, LoadingIcon, Center } from './styles';
import {
Title,
RepositoryName,
Form,
Badges,
Error,
LoadingIcon,
Center,
} from './styles';

interface Badge {
name: string;
Expand All @@ -18,7 +26,17 @@ interface Badge {

const Dashboard: React.FC = () => {
const [text, setText] = useState('');
const [badges, setBadges] = useState<Badge[]>([]);
const [prevRepoName, setPrevRepoName] = useState(
localStorage.getItem('@GithubBadges:Repo'),
);
const [badges, setBadges] = useState<Badge[]>(() => {
const hasBadges = JSON.parse(localStorage.getItem('@GithubBadges:Badges')!);

if (hasBadges && hasBadges.length > 0) {
return hasBadges;
}
return [];
});
const [inputError, setInputError] = useState('');
const [loading, setLoading] = useState(false);

Expand All @@ -44,6 +62,9 @@ const Dashboard: React.FC = () => {
const response = generateBadges(`${username}/${repository}`);

setBadges(response);
localStorage.setItem('@GithubBadges:Badges', JSON.stringify(response));
localStorage.setItem('@GithubBadges:Repo', `${username}/${repository}`);
setPrevRepoName(`${username}/${repository}`);
setText('');
setInputError('');
} catch (err) {
Expand Down Expand Up @@ -76,6 +97,8 @@ const Dashboard: React.FC = () => {

{inputError && <Error>{inputError}</Error>}

<RepositoryName>{prevRepoName}</RepositoryName>

<Center>
<LoadingIcon isLoading={loading} src={loadingImage} alt="Loading" />
</Center>
Expand Down
9 changes: 9 additions & 0 deletions src/pages/Dashboard/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ export const Title = styled.h1`
margin-top: 80px;
`;

export const RepositoryName = styled.h1`
font-size: 32px;
color: #3a3a3a;
max-width: 735px;
line-height: 56px;

margin-top: 40px;
`;

export const Form = styled.form<FormProp>`
margin-top: 40px;
max-width: 700px;
Expand Down