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
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ So What does matter to us?
7. Enjoy

**Finally** don't be afraid to ask anything from us.


### my roadmap for developing this project
1. break down the entire project to component
- navigation bar
- header
- main content (list of items)
2. create a very basic and static file structure and component
3. add eventHandlers and some more basic interactitvities
4. working on state and declaring the structrue for that
5. add api calls and final steps on interacivity
35,900 changes: 35,900 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "react-adsify",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.6.3",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
42 changes: 42 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React Adsify</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
3 changes: 3 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
155 changes: 155 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import React, { Component } from "react";
import ReactDOM from "react-dom";
// main style file
import "./style.css";

import Nav from "./NavBar.js"; // navigation bar
import Head from "./Head.js"; // header
import Main from "./Main.js"; // list of items
import Player from "./Player.js"; // vidoe player component

class App extends Component {
constructor(props) {
super(props);
this.state = {
video: 0,
player: 0,
playerLink: "",
videos: [],
clicks: []
}
this.handleMode = this.handleMode.bind(this);
this.showFull = this.showFull.bind(this);
this.closePlayer = this.closePlayer.bind(this);
}

componentDidMount() {
// intital api call for first list
let url = "https://picsum.photos/v2/list/?limit=60";
fetch(url)
.then(response => response.json())
.then(data => this.setState(state => {
let clicks = [];
for(let i = 0; i < data.length; i++){
clicks.push(0)
}
return { videos: data, clicks }
}))
.catch(err => console.log(err));

// event listener for reaching the end of the page to retrieve new items
window.addEventListener("scroll", (e) => {
let sY = window.scrollY;
let maxScroll = document.documentElement.offsetHeight - window.innerHeight;
if(sY == maxScroll) {
this.setState(state => {
let videos = [...state.videos];
let clicks = [...state.clicks]
let url = "https://picsum.photos/v2/list/?limit=60";
fetch(url)
.then(response => response.json())
.then(data => data.forEach(item => {
videos.push(item);
clicks.push(0);
}))
.catch(err => console.log(err));
return {videos, clicks};
});
}
});
}

// evenet listener for changing the mode of programm in navigation bar
handleMode(e) {
// set mode and clear state
this.setState({ video: Number(e.target.dataset.video), videos: [], clicks: []});
// add styles for active mode in navigation bar
document.querySelector(".nav__link--active").classList.remove("nav__link--active");
e.target.classList.add("nav__link--active");

// request new photo and rende new items
let url = "https://picsum.photos/v2/list/?limit=60";
fetch(url)
.then(response => response.json())
.then(data => this.setState(state => {
let clicks = [];
for(let i = 0; i < data.length; i++){
clicks.push(0)
}
return { videos: data, clicks }
}))
.catch(err => console.log(err));

}

// event listener to open video/banner in full page size
showFull(e) {
if (this.state.video){
this.setState({ player: 1 });

// trace clicks in photo mode
this.setState(state => {
let clicks = [...state.clicks];
clicks[Number(e.target.dataset.num)] += 1;
return { clicks };
});

}else {
// show phot in full page size
e.target.parentNode.classList.toggle("item--open");
let open = e.target.parentNode.classList.contains("item--open");
e.target.textContent = open ? "Close" : "View";

// trace clicks in photo mode
if(open) {
this.setState(state => {
let clicks = [...state.clicks];
clicks[Number(e.target.dataset.num)] += 1;
return { clicks };
});
};
};
}

// event listener for closing video player
closePlayer() {
if (this.state.player) {
this.setState({ player: 0 });
}
}

render() {
// creating list items to pass them as children to Main component
const list = this.state.videos.map((item, index) => {
return (
<li key={index} className="item">
<img className="item__img" src={item.download_url} alt="sorry!" />
<div className="item__text">
<h5 className="item__title">{item.author}</h5>
<p className="item__count">{this.state.clicks[index]}</p>
</div>
<button data-num={index} className="item__open" onClick={this.showFull}>View</button>
</li>
);
});

return (
<section>
<Nav
handleMode={this.handleMode}
name="Lorem Ipsum"
src="https://picsum.photos/300"/>
<Head />

<Main
children = {list}
video={this.state.video}
showFull={this.showFull}/>
<Player videoLink={this.state.videoLink} closePlayer={this.closePlayer} player={this.state.player}/>

</section>
);
}
};

export default App;
12 changes: 12 additions & 0 deletions src/Head.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.head {
display: flex;
align-items: center;
justify-content: flex-end;
width: 100%;
height: 8rem;
padding-right: 3rem;
font-size: 1.5rem;
background: #6986fd;
color: #323232;
border-bottom: 2px solid rgba(255, 255, 255, .4);
}
13 changes: 13 additions & 0 deletions src/Head.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";

import "./Head.css";

const Head = (props) => {
return (
<header className="head">
<h2 className="head__title">Explore & Enjoy</h2>
</header>
);
};

export default Head;
74 changes: 74 additions & 0 deletions src/Main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
.main__title {
font-size: 1.1rem;
padding: .4em 1em;
background: #031b88;
color: #ccc;
}
.container {
min-height: 75vh;
width: 100%;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
grid-gap: 1rem;
justify-content: center;
align-items: center;
list-style: none;
padding: 1em 1.5em;
}

.item {
background: rgba(255, 255, 255 ,.3);
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 1em;
backdrop-filter: blur(7px);
border: 1px solid white;
border-radius: .3em;
}
.item--open {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, .3);
justify-content: center;
border: none;
z-index: 9999;
}
.item--open .item__img {
display: inline-block;
width: 70vw;
height: auto;
max-height: 70vh;
}

.item__img {
display: inline-block;
width: 300px;
align-self: center;
}

.item__text {
display: flex;
align-items: center;
justify-content: space-around;
text-transform: uppercase;
font-weight: 600;
font-size: 1.1em;
margin: 1em;
}

.item__open {
outline: none;
border: 1px solid white;
background: rgba(255, 255, 255, .3);
border-radius: .2em;
cursor: pointer;
font-weight: 500;
letter-spacing: 1px;
}
.item__open:hover {
background: rgba(255, 255, 255, .6);
}
Loading