-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac15a3d
commit 59d44b6
Showing
7 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3944,6 +3944,11 @@ natural-compare@^1.4.0: | |
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" | ||
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw== | ||
|
||
naughty-words@^1.2.0: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/naughty-words/-/naughty-words-1.2.0.tgz#255f60bad94b430fb1216d05a3f4eec3e1061d64" | ||
integrity sha512-0iadX6fN+3NsfvIRtWmmpEX9VsoIQ6n9FwyIxmew9w5yzFNqMgs/Ky0eAC/z5xXSHtqlVoByiovdROikwH9SXQ== | ||
|
||
[email protected]: | ||
version "0.6.3" | ||
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.3.tgz#58e323a72fedc0d6f9cd4d31fe49f51479590ccd" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getServerEnv } from "@/utils/getServerEnv"; | ||
|
||
export const getGallery = async (query?:string, page?:number, video?:boolean) => { | ||
const API_URL = (await getServerEnv()).API_URL; | ||
let uri = query | ||
? `${API_URL}pexels/search/${query}?page=${page || 1}` | ||
: API_URL + "pexels/curated/" + (page || ''); | ||
if (video) { | ||
uri = `${API_URL}pexels/videos/search/${query || "cats"}?page=${page || 1}`; | ||
} | ||
const f = await fetch(uri); | ||
const d = await f.json(); | ||
return d | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use client'; | ||
import { useEffect, useState } from "react"; | ||
|
||
export function useWindowSize() { | ||
// Initialize state with undefined width/height so server and client renders match | ||
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/ | ||
const [windowSize, setWindowSize] = useState<{width?:number,height?:number,columnWidth?:number}>({ | ||
width: undefined, | ||
height: undefined, | ||
columnWidth: undefined | ||
}); | ||
const getColumnWidth = () => { | ||
if (typeof window === "undefined") { | ||
return 640; | ||
} | ||
let columnWidth = | ||
window?.innerWidth < 1536 | ||
? window?.innerWidth * 0.33 | ||
: window?.innerWidth / 4; | ||
if (window?.innerWidth < 1280) columnWidth = window?.innerWidth / 2; | ||
|
||
// if (window.innerWidth < 640) columnWidth = window.innerWidth; | ||
return columnWidth; | ||
}; | ||
|
||
useEffect(() => { | ||
// only execute all the code below in client side | ||
// Handler to call on window resize | ||
function handleResize() { | ||
// Set window width/height to state | ||
setWindowSize({ | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
columnWidth: getColumnWidth() | ||
}); | ||
} | ||
|
||
// Add event listener | ||
window.addEventListener("resize", handleResize); | ||
|
||
// Call handler right away so state gets updated with initial window size | ||
handleResize(); | ||
|
||
// Remove event listener on cleanup | ||
return () => window.removeEventListener("resize", handleResize); | ||
}, []); // Empty array ensures that effect is only run on mount | ||
return windowSize; | ||
} |