Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[#2PlaysAMonth]: Image Gallery - Create a responsive image gallery by using the free Unsplash API #974

Merged
merged 23 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
591be31
Successfully created an image gallery which uses unsplash API and has…
siddhantsiddh15 Feb 16, 2023
f3a9a9e
Some files were being asked to be stashed
siddhantsiddh15 Feb 16, 2023
ff5795d
Merge branch 'main' of https://github.com/siddhantsiddh15/react-play
siddhantsiddh15 Feb 16, 2023
a38ad8b
Installed material-ui/icons and changed styles.css a little
siddhantsiddh15 Feb 16, 2023
e2f8ad1
Ran npm lint and npm format command
siddhantsiddh15 Feb 16, 2023
7bac98a
formatted the styles.css
siddhantsiddh15 Feb 18, 2023
174a96a
Merge branch 'main' into unsplash-api-siddhantsiddh15
siddhantsiddh15 Feb 18, 2023
b13a13e
changed the className from .body to .unsplash-image-gallery-body
siddhantsiddh15 Feb 18, 2023
15315a1
Merge branch 'unsplash-api-siddhantsiddh15' of https://github.com/sid…
siddhantsiddh15 Feb 18, 2023
237fcc0
Merge branch 'main' into unsplash-api-siddhantsiddh15
atapas Feb 21, 2023
c5860aa
Random Quote Generator #973 was causing conflict. Resolved it.
siddhantsiddh15 Feb 21, 2023
343ccc6
removed the style for img from src/plays/image-gallery-using-unsplas…
siddhantsiddh15 Feb 21, 2023
8f60255
Merge branch 'main' into unsplash-api-siddhantsiddh15
Sachin-chaurasiya Feb 23, 2023
7614b5a
Merge branch 'main' into unsplash-api-siddhantsiddh15
siddhantsiddh15 Feb 24, 2023
79e9d4b
Merge branch 'main' into unsplash-api-siddhantsiddh15
siddhantsiddh15 Feb 26, 2023
70ed2f6
added the cover image
siddhantsiddh15 Feb 28, 2023
aced7cf
Merge branch 'unsplash-api-siddhantsiddh15' of https://github.com/sid…
siddhantsiddh15 Feb 28, 2023
484c6a0
added cover.png of size 135 kb
siddhantsiddh15 Feb 28, 2023
c96f345
Merge branch 'main' into unsplash-api-siddhantsiddh15
atapas Feb 28, 2023
d7b1bb5
Merge branch 'main' into unsplash-api-siddhantsiddh15
siddhantsiddh15 Mar 1, 2023
441d535
Merge branch 'main' into unsplash-api-siddhantsiddh15
siddhantsiddh15 Mar 4, 2023
9f4a2ba
Merge branch 'main' into unsplash-api-siddhantsiddh15
koustov Mar 5, 2023
441229e
Merge branch 'main' into unsplash-api-siddhantsiddh15
koustov Mar 5, 2023
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@emotion/react": "^11.9.3",
"@emotion/styled": "^11.9.3",
"@giscus/react": "^2.0.3",
"@mui/icons-material": "^5.11.9",
"@mui/material": "^5.9.1",
"@mui/styles": "^5.9.3",
"@nhost/react": "^0.9.0",
Expand All @@ -15,7 +16,7 @@
"@types/react": "^18.0.6",
"@types/react-dom": "^18.0.2",
"add": "^2.0.6",
"axios": "^0.27.2",
"axios": "^1.3.3",
"browser-image-compression": "^2.0.0",
"codemirror": "^5.65.7",
"date-fns": "^2.28.0",
Expand Down
40 changes: 20 additions & 20 deletions src/common/badges-dashboard/badge.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
.app-header-btn {
display: flex;
flex-direction: row;
align-items: center;
border: solid 1px var(--color-brand-primary);
border-radius: 2rem;
grid-gap: 0.4rem;
padding: 0.4rem 1.2rem;
font-size: var(--fs-sm);
text-decoration: none;
width: unset;
height: unset;
transition: all 0.12s ease-in-out;
}
display: flex;
flex-direction: row;
align-items: center;
border: solid 1px var(--color-brand-primary);
border-radius: 2rem;
grid-gap: 0.4rem;
padding: 0.4rem 1.2rem;
font-size: var(--fs-sm);
text-decoration: none;
width: unset;
height: unset;
transition: all 0.12s ease-in-out;
}

.app-header-btn--primary {
border: solid 2px var(--color-brand-primary);
background-color: var(--color-brand-primary);
color: var(--color-neutral-80);
grid-gap: 0.3rem;
margin-left: 0.4rem;
}
.app-header-btn--primary {
border: solid 2px var(--color-brand-primary);
background-color: var(--color-brand-primary);
color: var(--color-neutral-80);
grid-gap: 0.3rem;
margin-left: 0.4rem;
}
44 changes: 23 additions & 21 deletions src/common/playleaderboard/leaderBoard.css
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
.leaderboard-container {
border: 0 solid black;
border-radius: 5px;
background-color: white;
margin-top: 10px;
margin-bottom: 20px;
padding: 5px 2rem 1rem 2rem;
--tw-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
border: 0 solid black;
border-radius: 5px;
background-color: white;
margin-top: 10px;
margin-bottom: 20px;
padding: 5px 2rem 1rem 2rem;
--tw-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color),
0 8px 10px -6px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
var(--tw-shadow);
}

.leaderboard-table-cell {
padding: 6px !important;
padding: 6px !important;
}

.leaderboard-table-header {
font-weight: 700 !important;
font-family: var(--ff-accent) !important;
font-weight: 700 !important;
font-family: var(--ff-accent) !important;
}

.leaderboard-heading {
font-family: var(--ff-accent);
font-size: 32px !important;
font-family: var(--ff-accent);
font-size: 32px !important;
}

.leaderboard-text {
font-family: var(--ff-accent) !important;
font-size: var(--fs-md) !important;
font-family: var(--ff-accent) !important;
font-size: var(--fs-md) !important;
}

.leaderboard-loader {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
8 changes: 3 additions & 5 deletions src/common/playlists/playlist.css
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@
max-width: 600px;
}

.banner-button{
.banner-button {
margin-right: 10px;
background-color: rgba(255, 255, 255, 0.947);
border: none;
Expand All @@ -793,12 +793,10 @@
align-items: center;
gap: 4px;
}
.banner-button:hover{
.banner-button:hover {
background-color: #e6e6e6c3;
color: black;

}
.right-arrow-icon {
color: #25A0A7;
color: #25a0a7;
}

11 changes: 3 additions & 8 deletions src/plays/dad-jokes/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

## Play Screenshot

- ### **Light Mode**
- ### **Light Mode**

<div align="center">
<img src="https://i.postimg.cc/0N2n74Bf/light-mode.png" alt="Dad Jokes Screenshot" width="100%" target="_blank" />
<br>
</div>

- ### **Dark Mode**
- ### **Dark Mode**
<div align="center">
<img src="https://i.postimg.cc/3JXFV7M1/dark-mode.png" alt="Dad Jokes Screenshot" width="100%" target="_blank" />
<br>
Expand All @@ -33,7 +33,7 @@

## Creator Information

- ### **Bobby Sadhwani** - **[Linkedin](https://www.linkedin.com/in/bobby-sadhwani)**, **[Twitter](https://twitter.com/BOBBY__SADHWANI)**, **[Github](https://github.com/Bobby-coder)**, **[Portfolio](https://bobby-sadhwani.netlify.app)**
- ### **Bobby Sadhwani** - **[Linkedin](https://www.linkedin.com/in/bobby-sadhwani)**, **[Twitter](https://twitter.com/BOBBY__SADHWANI)**, **[Github](https://github.com/Bobby-coder)**, **[Portfolio](https://bobby-sadhwani.netlify.app)**

## Video

Expand All @@ -45,8 +45,3 @@
- ### **[React Icons](https://react-icons.github.io/react-icons/)**

### **Happy Coding!** 🤩





8 changes: 4 additions & 4 deletions src/plays/dad-jokes/components/jokeList/jokeList.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
z-index: 2;
}

.dad-jokes-play .dark .jokelist-sidebar{
.dad-jokes-play .dark .jokelist-sidebar {
background-color: #eee;
}

Expand All @@ -35,7 +35,7 @@
letter-spacing: 0;
}

.dad-jokes-play .dark .jokelist-sidebar-title h1{
.dad-jokes-play .dark .jokelist-sidebar-title h1 {
color: #0d0d0d;
}

Expand Down Expand Up @@ -73,7 +73,7 @@
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25);
}

.dad-jokes-play .dark .jokelist-sidebar-getmore button{
.dad-jokes-play .dark .jokelist-sidebar-getmore button {
color: #eee;
background-color: #0d0d0d;
}
Expand All @@ -88,7 +88,7 @@
box-shadow: 0 19px 38px rgba(0, 0, 0, 0.3), 0 15px 12px rgba(0, 0, 0, 0.1);
}

.dad-jokes-play .dark .jokelist-jokes{
.dad-jokes-play .dark .jokelist-jokes {
background-color: #0d0d0d;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import './styles.css';
import axios from 'axios';

import PlayHeader from 'common/playlists/PlayHeader';
import { useState, useEffect } from 'react';
import Photo from './components/Photo';
import SearchBar from './components/searchBar';

function ImageGalleryUsingUnsplashApi(props) {
// Your Code Start below.
const [loading, setLoading] = useState(false);
const [photos, setPhotos] = useState([]);
const [page, setPage] = useState(1);
const [query, setQuery] = useState('');

const clientID = 'client_id=LLC2ARXdcZNo-Hqh5IxJlveXFhOM_C1JfEq2YruC958';

const URL = 'https://api.unsplash.com/photos';

const searchURL = 'https://api.unsplash.com/search/photos';

// create a function
// which will fetch the url of the unsplash api
// on success will populate the photos
async function fetchImages() {
setLoading(true);

let url;
const urlPage = `?page=${page}`;

const urlQuery = `&query=${query}`;

if (query) {
// // https://api.unsplash.com/search/photos?page=1&query=office&client_id=LLC2ARXdcZNo-Hqh5IxJlveXFhOM_C1JfEq2YruC958 This is the format for API calling
url = `${searchURL}${urlPage}${urlQuery}&${clientID}`;
} else {
// https://api.unsplash.com/photos/?client_id=YOUR_ACCESS_KEY
url = `${URL}/?${clientID}`;
}

try {
// const response = await fetch(url);

const response = await axios.get(url);
const data = response.data;

let tempPhotoArray;
if (query && page === 1) {
tempPhotoArray = data.results;
} else if (query) {
tempPhotoArray = [...photos, ...data.results];
} else {
tempPhotoArray = [...data];
}

setPhotos(tempPhotoArray);
setLoading(false);
} catch (err) {
setLoading(false);

console.warn(err);
}
}

useEffect(() => {
fetchImages();
}, [page]);

const onScroll = () => {
const scrollTop = document.documentElement.scrollTop;
const scrollHeight = document.documentElement.scrollHeight;
const clientHeight = document.documentElement.clientHeight;

if (!loading && scrollTop + clientHeight >= scrollHeight - 2) {
setPage(page + 2);
}
};

useEffect(() => {
window.addEventListener('scroll', onScroll);

return () => window.removeEventListener('scroll', onScroll);
}, [photos]);

function handleFormSubmit(e) {
// preventDefault will stop the form from getting submitted over and over again automatically

e.preventDefault();
setPage(1);
fetchImages();
}

return (
<>
<div className="play-details">
<PlayHeader play={props} />
<div className="play-details-body">
{/* Your Code Starts Here */}
<div className="body">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would certainly change the class name from body to something more unique :) How about unsplash-ig?

<section id="searchBar">
<SearchBar setQuery={setQuery} onFormSubmit={handleFormSubmit} />
</section>

<section className="photoGrid">
<div className="searchedPhotos">
{photos.map((image, index) => {
return <Photo key={index} {...image} />;
})}
</div>
</section>
</div>
{/* Your Code Ends Here */}
</div>
</div>
</>
);
}

export default ImageGalleryUsingUnsplashApi;
35 changes: 35 additions & 0 deletions src/plays/image-gallery-using-unsplash-api/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Image Gallery using UnSplash API

A responsive image gallery by using the free Unsplash API

## Play Demographic

- Language: js
- Level: Intermediate

## Creator Information

- User: siddhantsiddh15
- Gihub Link: https://github.com/siddhantsiddh15
- Blog:
- Video:

## Implementation Details

Update your implementation idea and details here

### Create the search bar

Start by creating a form that takes the input and has a submit button.

### Create the section for images

This is a simple project and it will need a section(portion on the webpage) where the images will be loaded after successfully fetching the unsplash api.

## Consideration

Update all considerations(if any)

## Resources

Update external resources(if any)
Loading