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
57 changes: 28 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@ This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next

## Getting Started

First, install dependencies:
First, run the development server:

```bash
npm install
# or
yarn
```

## Api key
* Create account and generate API key for Pexels API https://www.pexels.com/join-consumer/
* Add .env.local file to your root folder and inside add your Pexels key to the API_KEY variable.

## Running development server
```bash
npm run dev
# or
yarn dev
```

## Tasks

#### Add list of images
- Display images by 5 in row
- After clicking image, image should be visible in the modal. Also, author of the photo should be displayed in right bottom corner
- Modal can be closed by clicking 'X' icon, outside of photo and pressing 'Esc' key on the keyboard.

#### Searching images
- Add search field above image list
- Images should be filtered by typed text.
- Request should be fetched when user stopped typing (not for each letter ;) )
- User should be able to choose how many images is visible per page. Available values: 10, 25, 50,
- List should be paginated

#### Terms and condition page
- Add link in the footer of app 'Terms and Condition'. Link should provide to another page
- Get content for page from http://legalipsum.com/?count=2
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

**Api key**

add .env.local file to your root folder and inside add your pexels key to the API_KEY variable.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

8 changes: 6 additions & 2 deletions components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Container, Menu } from 'semantic-ui-react';
import { Icon } from 'semantic-ui-react'

const Layout = ({ children }) => {
interface IChildren {
children: Node,
};

const Layout = ({ children } : IChildren) => {
return (
<>
<Menu>
Expand All @@ -11,7 +15,7 @@ const Layout = ({ children }) => {
<Container>
{ children }
</Container>
<Container textAlign="center">
<Container textAlign="center" style={{marginTop: '5rem'}}>
@Interview Frontend App 2021
</Container>
</>
Expand Down
29 changes: 22 additions & 7 deletions components/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { Photo } from '../interfaces/photos';
import { Container, Grid, Image } from 'semantic-ui-react';
import { Photo, PhotosResponse } from '../interfaces/photos';
import Modal from './Modal';

const Main = ({ photos }) => {
const Main = ({ photos }: PhotosResponse) => {
return (
<div>
<ul>
{photos && photos.photos.map((el: Photo) => (
<li key={el.id}><img src={el.src.small}/></li>
))}
</ul>
<Container>
<Grid
centered
columns={5}
>
{photos && photos.map((photo: Photo) => (
<Grid.Column
key={photo.id}
textAlign="center"
>
<Modal
trigger={<Image src={photo.src.small} alt="" wrapped centered rounded style={{cursor: "pointer"}}/>}
photo={photo}
/>
</Grid.Column>
))}
</Grid>
</Container>
</div>
)
};
Expand Down
45 changes: 45 additions & 0 deletions components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useState } from 'react';
import { Button, Image, Modal, Segment } from 'semantic-ui-react';
import { Photo } from '../interfaces/photos';

interface IProps {
photo: Photo,
trigger: React.ReactNode,
};

const ModalElement = ({trigger, photo}: IProps) => {
const [open, setOpen] = useState(false);

return (
<Modal
onClose={() => setOpen(false)}
onOpen={() => setOpen(true)}
open={open}
trigger={trigger}
style={{width: 'auto'}}
>
<Modal.Actions>
<Button
basic
icon="close"
onClick={() => setOpen(false)}
>
</Button>
</Modal.Actions>
<Modal.Content style={{padding: 0}}>
<Image
size='big'
src={photo.src.large}
alt=""
/>
</Modal.Content>
<Modal.Description>
<Segment
basic
textAlign="right">{photo.photographer}</Segment>
</Modal.Description>
</Modal>
)
};

export default ModalElement;
9 changes: 5 additions & 4 deletions interfaces/photos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export type Photo = {
};

export type PhotosResponse = {
photos: Photo[],
total_results: number,
page: number,
per_page: number
photos: Photo[];
total_results: number;
page: number;
per_page: number;
next_page: string;
};
Loading