From 24596907c7a40b2c3bf4c452d7e158c94a1e6657 Mon Sep 17 00:00:00 2001 From: evan slack Date: Thu, 10 Aug 2023 16:23:12 -0400 Subject: [PATCH 1/7] store state in query params and add color filter --- web/components/gallery.js | 226 +++++++++++++++++++++++++++--- web/components/gallery.module.css | 15 ++ web/package-lock.json | 17 +++ web/package.json | 1 + 4 files changed, 237 insertions(+), 22 deletions(-) diff --git a/web/components/gallery.js b/web/components/gallery.js index 8bb9bb9..60dd6fb 100644 --- a/web/components/gallery.js +++ b/web/components/gallery.js @@ -5,12 +5,14 @@ import InfiniteGallery from "../components/infiniteGallery"; import ScrollTop from "../components/scrollTop"; import { useState, useEffect } from "react"; import useKeyPress from "../hooks/useKeyPress"; +import { useQueryState, queryTypes } from "next-usequerystate"; import { IconSearch, IconArrowsSort, IconAdjustmentsHorizontal, + IconPalette, + IconCheck, } from "@tabler/icons"; -import useQuery from "../stores/query"; import { TextInput, @@ -18,7 +20,9 @@ import { SegmentedControl, Menu, Radio, + Checkbox, } from "@mantine/core"; + import { baseURL } from "../constants.js"; async function makeRequest(queryParams) { @@ -28,7 +32,7 @@ async function makeRequest(queryParams) { return data; } -function filterQueryParams(sort, nsfw, bw, sprocket, search) { +function filterQueryParams(sort, nsfw, bw, sprocket, search, color) { let queryParams = "?" + "sort=" + sort; switch (nsfw) { @@ -62,34 +66,71 @@ function filterQueryParams(sort, nsfw, bw, sprocket, search) { queryParams = queryParams.concat("&title=" + search); } + if (color !== "") { + queryParams = queryParams.concat("&color=" + color); + if (color === "black" || color === "gray") { + queryParams = queryParams.concat("&min_color=" + "0.8"); + } + if (color === "white") { + queryParams = queryParams.concat("&min_color=" + "0.6"); + } + if (color === "teal") { + queryParams = queryParams.concat("&min_color=" + "0.25"); + } + if (color === "navy" || color === "green") { + queryParams = queryParams.concat("&min_color=" + "0.15"); + } + } + queryParams = queryParams.concat("&page_size=" + 100); return queryParams; } export default function Gallery(props) { - const { search, sort, nsfw, bw, sprocket } = useQuery((store) => ({ - search: store.search, - sort: store.sort, - nsfw: store.nsfw, - bw: store.bw, - sprocket: store.sprocket, - })); - - const { setSearch, setSort, setNsfw, setBw, setSprocket } = useQuery( - (store) => ({ - setSearch: store.setSearch, - setSort: store.setSort, - setNsfw: store.setNsfw, - setBw: store.setBw, - setSprocket: store.setSprocket, - }) + // querystate + const [sort, setSort] = useQueryState( + "sort", + queryTypes.string.withDefault("latest") + ); + const [nsfw, setNsfw] = useQueryState( + "nsfw", + queryTypes.string.withDefault("exclude") + ); + const [bw, setBw] = useQueryState( + "bw", + queryTypes.string.withDefault("exclude") ); + const [sprocket, setSprocket] = useQueryState( + "sprocket", + queryTypes.string.withDefault("include") + ); + const [search, setSearch] = useQueryState( + "text", + queryTypes.string.withDefault("") + ); + const [color, setColor] = useQueryState( + "color", + queryTypes.string.withDefault("") + ); + + const handleColorClick = (event) => { + let clickedColor = event.target.id; + if (clickedColor === color) { + setColor(null); + } else { + setColor(clickedColor); + } + }; + + const blackCheck = () => { + ; + }; const [response, setResponse] = useState(props.data); const updateRequest = async () => { - let request = filterQueryParams(sort, nsfw, bw, sprocket, search); + let request = filterQueryParams(sort, nsfw, bw, sprocket, search, color); const response = await makeRequest(request); setResponse(response); }; @@ -98,13 +139,154 @@ export default function Gallery(props) { useEffect(() => { updateRequest(); - }, [sort, nsfw, bw, sprocket, returnPress]); + }, [sort, nsfw, bw, sprocket, color, returnPress]); return (
+ + + + + + with color +
+ + + + + + + + + +
+
+
+ setSearch(event.currentTarget.value)} + value={textTemp} + onChange={(event) => setTextTemp(event.currentTarget.value)} icon={} placeholder="films, cameras, places..." /> diff --git a/web/components/gallery.module.css b/web/components/gallery.module.css index fd4f512..06f2628 100644 --- a/web/components/gallery.module.css +++ b/web/components/gallery.module.css @@ -65,7 +65,7 @@ padding-right: 1rem; padding-left: 1rem; padding-top: 0.5rem; - padding-bottom: 0.5rem; + padding-bottom: 1rem; } .colorButton { diff --git a/web/components/imageTag.js b/web/components/imageTag.js index e27ce39..a14d3e2 100644 --- a/web/components/imageTag.js +++ b/web/components/imageTag.js @@ -34,7 +34,18 @@ export default function ImageTag(props) { Object.hasOwn(post, "keywords") && post.keywords.length > 0 ? post.keywords .map((item) => { - return {item.word}; + return ( + + + {item.word} + + + ); }) .slice(0, 15) : []; diff --git a/web/components/imageTag.module.css b/web/components/imageTag.module.css index b3fe469..0b8b27f 100644 --- a/web/components/imageTag.module.css +++ b/web/components/imageTag.module.css @@ -100,6 +100,11 @@ background-color: #f5f5f5; /* box-shadow: 0.5px 0.5px 20px 0.5px lightgray; */ } +.keyword:hover { + color: #f5f5f5; + background-color: #636363; + border-color: #636363; +} .title { font-size: 1.3rem; From a40859fbbb3c705861eedb0ef57e63d73b1d470d Mon Sep 17 00:00:00 2001 From: evan slack Date: Thu, 10 Aug 2023 20:15:41 -0400 Subject: [PATCH 6/7] ui updates --- web/components/gallery.js | 48 ++++++++++++++++++++++++------- web/components/grid.js | 2 +- web/components/gridImage.js | 10 +++---- web/components/imagePage.js | 4 +-- web/components/infiniteGallery.js | 2 +- web/pages/_app.js | 2 +- 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/web/components/gallery.js b/web/components/gallery.js index aeabd1d..d0d1766 100644 --- a/web/components/gallery.js +++ b/web/components/gallery.js @@ -4,6 +4,7 @@ import Footer from "./footer"; import InfiniteGallery from "../components/infiniteGallery"; import ScrollTop from "../components/scrollTop"; import { useState, useEffect } from "react"; +import { useBreakpoint } from "../providers/breakpoint.js"; import useKeyPress from "../hooks/useKeyPress"; import { useQueryState, queryTypes } from "next-usequerystate"; import { @@ -155,6 +156,24 @@ export default function Gallery(props) { const returnPress = useKeyPress("Enter"); + const breakpoints = useBreakpoint(); + + let onlyIcon = false; + if (breakpoints["xs"] || breakpoints["sm"]) { + onlyIcon = true; + } + + // const textPlaceholder = () => { + // onlyIcon ? "films, cameras..." : "films, cameras, places..."; + // }; + + const textPlaceholder = () => { + const placeholder = onlyIcon + ? "films, cameras..." + : "films, cameras, places..."; + return placeholder; + }; + useEffect(() => { updateRequest(); }, [sort, nsfw, bw, sprocket, color, text, returnPress]); @@ -169,12 +188,14 @@ export default function Gallery(props) { @@ -310,12 +331,14 @@ export default function Gallery(props) { @@ -366,12 +389,17 @@ export default function Gallery(props) { @@ -434,7 +462,7 @@ export default function Gallery(props) { value={textTemp} onChange={(event) => setTextTemp(event.currentTarget.value)} icon={} - placeholder="films, cameras, places..." + placeholder={textPlaceholder()} />
diff --git a/web/components/grid.js b/web/components/grid.js index a52fc6c..ac154ab 100644 --- a/web/components/grid.js +++ b/web/components/grid.js @@ -5,7 +5,7 @@ import GridImage from "./gridImage"; export default function Grid(props) { const breakpoints = useBreakpoint(); - let numColumn = 5; + let numColumn = 6; if (breakpoints["xs"]) { numColumn = 2; } else if (breakpoints["sm"]) { diff --git a/web/components/gridImage.js b/web/components/gridImage.js index 0d0b145..828e3b5 100644 --- a/web/components/gridImage.js +++ b/web/components/gridImage.js @@ -3,6 +3,9 @@ import Link from "next/link"; export default function GridImage(props) { let post = props.post; + if (post == null) { + return; + } let low = post.images[0]; let medium = post.images[1]; @@ -16,12 +19,7 @@ export default function GridImage(props) { } return ( - +
+

thats all folks, go take some pictures...

} diff --git a/web/pages/_app.js b/web/pages/_app.js index bcfaade..06c6dea 100644 --- a/web/pages/_app.js +++ b/web/pages/_app.js @@ -5,7 +5,7 @@ import { MantineProvider } from "@mantine/core"; import { NavigationProgress } from "@mantine/nprogress"; const queries = { - xs: "(max-width: 360px)", + xs: "(max-width: 480px)", sm: "(max-width: 720px)", md: "(max-width: 1024px)", lg: "(max-width: 1440px)", From f765376f904b287d7edbf5e784365e75600097ce Mon Sep 17 00:00:00 2001 From: evan slack Date: Thu, 10 Aug 2023 20:31:16 -0400 Subject: [PATCH 7/7] update rate limit doc --- web/components/documentation.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web/components/documentation.js b/web/components/documentation.js index 9164622..a7b6010 100644 --- a/web/components/documentation.js +++ b/web/components/documentation.js @@ -246,13 +246,15 @@ export default function Documentation() {

Rate Limiting

- The Analogdb API currently places a limit of 30 requests/min. + The Analogdb API currently places a limit of 60 requests/min. Current rate limit status is returned in response headers after each - request. + request including remaining requests and reset time in unix epoch + seconds.

- X-Ratelimit-Limit: 30 -

X-Ratelimit-Remaining: 29 + x-ratelimit-limit: 60 +

x-ratelimit-remaining: 59 +

x-ratelimit-reset: 1691712960