Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat/People #178

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
18,224 changes: 18,224 additions & 0 deletions arturito/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions arturito/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
]
},
"dependencies": {
"@craco/craco": "^6.2.0",
"@craco/craco": "^5.9.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
Expand All @@ -42,8 +42,8 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"swr": "^0.5.6",
"react-scripts": "^5.0.1",
"swr": "^0.5.7",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion arturito/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Header from './components/Header';
import MainContainer from './containers/Main';


const App = () => (
<div className="h-full w-full bg-gray-800 text-white">
<Header />

<MainContainer />
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion arturito/src/components/HomeSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const Button = ({ text, href }: { text: string; href: string }) => (
const HomeSection = () => (
<div className="p-3 space-y-3">
<p className="text-lg">¡Elegí una sección!</p>
<Button text="Documentación" href="https://www.swapi.it/documentation" />
<Button text="Documentación" href="https://swapi.dev/api" />
</div>
);

export default HomeSection;
//documentation
47 changes: 47 additions & 0 deletions arturito/src/components/PeopleSelection/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import useSWR from 'swr';
import { swGet } from '../../utils/fetcher';
import Table from '../Table';

const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
},
{
title: 'Birth Year',
dataIndex: 'birth_year',
key: 'birth_year',
},
{
title: 'Height (meters)',
dataIndex: 'height',
key: 'height',
render: (height) => (height ? `${parseInt(height) / 100} m` : 'N/A'),
},
{
title: 'Films',
dataIndex: 'films',
key: 'films_count',
render: (films) => (films ? films.length : 0),
},
];

const People = () => {
const { data, error } = useSWR('/people', swGet);

if (error) {
return <div className="px-2">Error</div>;
}
if (!data) {
return <div className="px-2">Wait...</div>;
}

return (
<div>
<Table columns={columns} data={data.results} />
</div>
);
};

export default People;
4 changes: 2 additions & 2 deletions arturito/src/components/PlanetsSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const columns = [
dataIndex: 'name',
key: 'name',
},
{
{
title: 'Climate',
dataIndex: 'climate',
key: 'climate',
Expand Down Expand Up @@ -43,7 +43,7 @@ const Planets = () => {

return (
<div>
<Table columns={columns} data={data.results.slice(0, 3)} /* :D */ />
<Table columns={columns} data={data.results} /* :D */ />
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion arturito/src/components/SectionSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SectionButton = ({ path }: { path: Path }) => {
const SectionSelector = () => (
<div className="p-2 space-x-4">
{Object.keys(paths).map((path) => (
<SectionButton path={paths[path]} />
<SectionButton key={path} path={paths[path]} />
))}
</div>
);
Expand Down
54 changes: 54 additions & 0 deletions arturito/src/components/StarshipsSelection/starshipsSelection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import useSWR from 'swr';
import { swGet } from '../../utils/fetcher';
import Table from '../Table';


const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'model',
},
{
title: 'Model',
dataIndex: 'model',
key: 'model',
},
{
title: 'Manufacturer',
dataIndex: 'manufacturer',
key: 'manufacturer',
},
{
title: 'Passengers',
dataIndex: 'passengers',
key: 'passengers',
},
{
title: 'Films',
dataIndex: 'films',
key: 'films_count',
render: (films) => (films ? films.length : 0),
},
];


const Starships = () => {
const { data, error } = useSWR('/starships', swGet);

if (error) {
return <div className="px-2">Oh oh!</div>;
}
if (!data) {
return <div className="px-2">Loading...</div>;
}

return (
<div>
<Table columns={columns} data={data.results} /* :D */ />
</div>
);
};

export default Starships;

30 changes: 4 additions & 26 deletions arturito/src/containers/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { paths } from '../paths';
import SectionSelector from '../../components/SectionSelector';
import Home from '../../components/HomeSection';
import Planets from '../../components/PlanetsSection';
import People from '../../components/PeopleSelection';
import Starships from '../../components/StarshipsSelection/starshipsSelection';

const MainContainer = () => {
const location = useLocation();
Expand All @@ -29,35 +31,11 @@ const MainContainer = () => {
</Route>

<Route path={paths.starships.href}>
<div className="p-3">
<p className="font-bold text-xl"># TODO</p>
<p>
Agregar tabla con las starships sacadas de la API. Mostrar para
cada starship: name, model, manufacturer, passengers, cantidad de
films. Codear en un componente aparte tal como {'<Planets>'}.
</p>
<p>
<a href="https://swapi.it/documentation#starships">
https://swapi.it/documentation#starships
</a>
</p>
</div>
<Starships/>
</Route>

<Route path={paths.people.href}>
<div className="p-3">
<p className="font-bold text-xl"># TODO</p>
<p>
Agregar tabla con los personajes sacados de la API. Mostrar para
cada persona: name, birth_year, height (en metros), cantidad de
films. Codear en un componente aparte tal como {'<Planets>'}.
</p>
<p>
<a href="https://swapi.it/documentation#people">
https://swapi.it/documentation#people
</a>
</p>
</div>
<People />
</Route>

<Route path={paths.home.href}>
Expand Down
2 changes: 1 addition & 1 deletion arturito/src/utils/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';

// Possible alternative: 'https://swapi.dev/api'
const baseURL = 'https://www.swapi.it/api';
const baseURL = 'https://swapi.dev/api'; //'https://www.swapi.it/api'

export const swGet = (url: string) =>
axios.get(url, { baseURL }).then((res) => res.data);
Loading