Skip to content

Commit

Permalink
add user page
Browse files Browse the repository at this point in the history
  • Loading branch information
jrsmarcilio committed Oct 21, 2021
1 parent 083abd7 commit f1b6b0a
Show file tree
Hide file tree
Showing 25 changed files with 925 additions and 48 deletions.
15 changes: 12 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"presets": ["next/babel"],
"plugins": [["styled-components", { "ssr": true }]]
}
"presets": [
"next/babel"
],
"plugins": [
[
"styled-components",
{
"ssr": true
}
]
]
}
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_UNSPLASH_API_KEY=_-11Cu6zCehO-IGPcUHSAdOzOezV_9k0ZukKWPneV3Q
7 changes: 7 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
reactStrictMode: true,

images: {
domains: ["images.unsplash.com"],
},
};
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
"start": "next start"
},
"dependencies": {
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2",
"axios": "^0.23.0",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-elastic-carousel": "^0.11.5",
"react-is": "^17.0.2",
"styled-components": "^5.2.3"
"react-toastify": "^8.0.3",
"styled-components": "^5.2.3",
"unsplash-js": "^7.0.15"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/node": "15.0.0",
"@types/react": "17.0.4",
"@types/react-dom": "17.0.3",
Expand Down
30 changes: 0 additions & 30 deletions pages/_document.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions pages/index.tsx

This file was deleted.

Binary file added public/image/mobile-nav.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/image/shortcut-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions src/components/CarouselPerfil/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { useEffect, useState } from 'react';
import Image from 'next/image';
import Router from 'next/router'

import Carousel from "react-elastic-carousel";

import { CarouselPerfilStyle } from "./styles";
import api from '@/service/api';
import React from 'react';
import { toast } from 'react-toastify';

import { UserCarousel } from '@/interface'
import { CardContent, Typography } from '@material-ui/core';
import { CardUserCarousel } from '@/styles/MaterialGuide/'


export default function CarouselPerfil() {
const [userCarousel, setUserCarousel] = useState<any[]>([]);

useEffect(() => {
function fetchApiUnsplash() {
api.get('search/users?', {
params: {
query: 'usa',
client_id: process.env.NEXT_PUBLIC_UNSPLASH_API_KEY
}
}).then((response: any) => setUserCarousel(response.data.results)
).catch(error => toast.warning(error.message));
}
fetchApiUnsplash();
}, [])

const handleRedirectUserPerfil = (username: string) => () => {
Router.push(`/users/${username}`)
}

return (
<CarouselPerfilStyle>
<Carousel
showArrows={false}
isRTL
itemPadding={[0, 5]}
breakPoints={
[
{ width: 1, itemsToShow: 5 },
{ width: 550, itemsToShow: 6 },
{ width: 768, itemsToShow: 8 },
{ width: 1200, itemsToShow: 12 },
]
}
>
{userCarousel.map((item: UserCarousel, index: number) => (
<CardUserCarousel
key={index}
onClick={handleRedirectUserPerfil(item.username)}
>
<div className="profile-picture">
<Image src={item.profile_image?.medium} alt={`Profile picture of ${item.name}`} width={56} height={56} />
</div>
<CardContent>
<Typography variant="h2" component="p">
{item.name}
</Typography>
</CardContent>
</CardUserCarousel>
))}
</Carousel>
</CarouselPerfilStyle >
);
}
31 changes: 31 additions & 0 deletions src/components/CarouselPerfil/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import styled from "styled-components";

export const CarouselPerfilStyle = styled.div`
width: 100%;
height: 100px;
a {
text-decoration: none;
cursor: pointer;
}
.rec {
margin-top: 0;
}
.rec-dot {
box-shadow: none;
border: none;
background: none;
box-shadow: none;
}
.rec-item-wrapper {
width: 80px;
}
.MuiTypography-h2 {
color: #262626;
font-size: 12px;
line-height: 16px;
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
white-space: nowrap;
}
`;
17 changes: 17 additions & 0 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Link from 'next/link';
import Image from 'next/image';

import { HeaderStyled } from './styles';

export default function Header() {
return (
<HeaderStyled>
<Link href="/">
<a target="_self">
<Image src="/image/mobile-nav.png" alt="instagram brand icon"
width={103} height={29} />
</a>
</Link>
</HeaderStyled>
)
}
13 changes: 13 additions & 0 deletions src/components/Header/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import theme from "@/styles/theme";
import styled from "styled-components";

export const HeaderStyled = styled.div`
width: 414px;
display: flex;
justify-content: center;
align-items: center;
background: ${theme.palette.background.default};
border-bottom: 1px solid ${theme.palette.text.disabled};
`;
21 changes: 21 additions & 0 deletions src/interface/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface UserInstagram {
instagram_username: string;
name: string;
bio: string;
location: string;
links: Array<string>;
profile_image: Array<string>;
following_count: number;
followers_count: number;
total_photos: number;
}
export interface UserPhotosData {
photos: Array<string>;
}

export interface UserCarousel {
username: string;
id: string;
name: string;
profile_image: any;
}
64 changes: 64 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import Document, { DocumentContext, Html, Head, Main, NextScript } from 'next/document';
import { ServerStyleSheets } from '@material-ui/styles';
import { ServerStyleSheet } from 'styled-components';

class MyDocument extends Document {
render() {
return (
<Html lang="pt">
<Head>

<meta charSet="UTF-8" />

<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"
rel="stylesheet"
/>
<link
rel="shortcut icon"
href="/image/shortcut-icon.jpg"
type="image/x-icon"
/>

</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}

MyDocument.getInitialProps = async (ctx: DocumentContext) => {

const materialSheet = new ServerStyleSheets();
const styledComponentSheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;

try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) =>
styledComponentSheet.collectStyles(
materialSheet.collect(<App {...props} />),
),
});

const initialProps = await Document.getInitialProps(ctx);

return {
...initialProps,
styles: [
...React.Children.toArray(initialProps.styles),
materialSheet.getStyleElement(),
styledComponentSheet.getStyleElement(),
],
};
} finally {
styledComponentSheet.seal();
}
};

export default MyDocument;
16 changes: 16 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HomeStyled } from '@/styles/pages/home';

import CarouselPerfil from '@/components/CarouselPerfil';
import Header from '@/components/Header';

export default function Home() {
return (
<HomeStyled>
<Header />

<div className="home-carousel-content">
<CarouselPerfil />
</div>
</HomeStyled>
)
}
Loading

0 comments on commit f1b6b0a

Please sign in to comment.