even better masonry layout and add sort by date option to gallery

This commit is contained in:
Chuck Dries 2022-06-21 23:52:24 -07:00
parent 9ec2791b82
commit dbb71561d7
No known key found for this signature in database
GPG Key ID: A00B7AEAE1DC5BE6
8 changed files with 2059 additions and 41 deletions

BIN
data/gallery/DSC09546.jpg (Stored with Git LFS)

Binary file not shown.

View File

@ -1,3 +1,5 @@
import * as React from "react";
import { darkTheme, Provider } from "@adobe/react-spectrum";
import "./src/styles/global.css"; import "./src/styles/global.css";
const env = const env =
@ -6,11 +8,11 @@ export const onRouteUpdate = function () {
if (env === "production" && typeof window.plausible === "object") { if (env === "production" && typeof window.plausible === "object") {
window.plausible("pageview"); window.plausible("pageview");
// eslint-disable-next-line // eslint-disable-next-line
_paq.push(['setCustomUrl', '/' + window.location.pathname]); _paq.push(["setCustomUrl", "/" + window.location.pathname]);
// eslint-disable-next-line // eslint-disable-next-line
_paq.push(['setDocumentTitle', document.title]); _paq.push(["setDocumentTitle", document.title]);
// eslint-disable-next-line // eslint-disable-next-line
_paq.push(['trackPageView']); _paq.push(["trackPageView"]);
} }
}; };
// import * as React from 'react'; // import * as React from 'react';
@ -26,6 +28,19 @@ export const onRouteUpdate = function () {
// p: MyParagraph, // p: MyParagraph,
// }; // };
// export const wrapRootElement = ({ element }) => (
// <MDXProvider components={components}>{element}</MDXProvider> export const wrapRootElement = ({ element }) => (
// ); <Provider
UNSAFE_style={{
background: "transparent !important",
color: 'unset !important'
}}
colorScheme="dark"
theme={darkTheme}
>
{element}
</Provider>
);
// {/* // <MDXProvider components={components}>{element}</MDXProvider> */}

View File

@ -1 +1,16 @@
import * as React from "react";
import { darkTheme, Provider } from "@adobe/react-spectrum";
import "./src/styles/global.css"; import "./src/styles/global.css";
export const wrapRootElement = ({ element }) => (
<Provider
UNSAFE_style={{
background: "transparent !important",
color: 'unset !important'
}}
colorScheme="dark"
theme={darkTheme}
>
{element}
</Provider>
);

View File

@ -21,6 +21,7 @@
"pretty": "prettier --write ." "pretty": "prettier --write ."
}, },
"dependencies": { "dependencies": {
"@adobe/react-spectrum": "^3.19.0",
"@mdx-js/mdx": "^1.6.22", "@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22", "@mdx-js/react": "^1.6.22",
"autoprefixer": "^10.2.6", "autoprefixer": "^10.2.6",

View File

@ -51,23 +51,28 @@ const MasonryGallery = ({
R.reduce( R.reduce(
(acc, currentAspect) => { (acc, currentAspect) => {
const currentRow = acc.pop(); const currentRow = acc.pop();
if (currentRow.aspect + currentAspect > targetAspect) { const currentDiff = Math.abs(targetAspect - currentRow.aspect);
const diffIfImageIsAddedToCurrentRow = Math.abs(
targetAspect - (currentRow.aspect + currentAspect)
);
// add image to current row if it gets us closer to our target aspect ratio
if (currentDiff > diffIfImageIsAddedToCurrentRow) {
return [ return [
...acc, ...acc,
currentRow,
{ {
aspect: currentAspect, aspect: currentRow.aspect + currentAspect,
images: 1, images: currentRow.images + 1,
startIndex: currentRow.startIndex + currentRow.images, startIndex: currentRow.startIndex,
}, },
]; ];
} }
return [ return [
...acc, ...acc,
currentRow,
{ {
aspect: currentRow.aspect + currentAspect, aspect: currentAspect,
images: currentRow.images + 1, images: 1,
startIndex: currentRow.startIndex, startIndex: currentRow.startIndex + currentRow.images,
}, },
]; ];
}, },
@ -128,8 +133,8 @@ const MasonryGallery = ({
{debug && ( {debug && (
<span className="text-white z-20 absolute bg-black"> <span className="text-white z-20 absolute bg-black">
hsl( hsl(
{image.fields.imageMeta.dominantHue[0]},{' '} {image.fields.imageMeta.dominantHue[0]},{" "}
{(image.fields.imageMeta.dominantHue[1] * 100).toFixed(2)}%,{' '} {(image.fields.imageMeta.dominantHue[1] * 100).toFixed(2)}%,{" "}
{(image.fields.imageMeta.dominantHue[2] * 100).toFixed(2)}% ) {(image.fields.imageMeta.dominantHue[2] * 100).toFixed(2)}% )
</span> </span>
)} )}

View File

@ -35,6 +35,7 @@ const IndexPage = ({
const image = React.useMemo(() => { const image = React.useMemo(() => {
return images[imageIndex]; return images[imageIndex];
}, [images, imageIndex]); }, [images, imageIndex]);
console.log(image);
const shuffleImage = React.useCallback( const shuffleImage = React.useCallback(
(currentImage) => { (currentImage) => {
@ -214,6 +215,7 @@ export const query = graphql`
sourceInstanceName: { eq: "gallery" } sourceInstanceName: { eq: "gallery" }
base: { base: {
in: [ in: [
"DSC06616.jpg" # B&W abstract ## KEEP ON TOP
# "20160530-DSC09108.jpg" # portrait red flowers # "20160530-DSC09108.jpg" # portrait red flowers
# # "DSC00201.jpg" # duck # # "DSC00201.jpg" # duck
# "DSC04905.jpg" # purple layers # "DSC04905.jpg" # purple layers
@ -245,7 +247,6 @@ export const query = graphql`
"DSC02615.jpg" # rori iredale beach field camera "DSC02615.jpg" # rori iredale beach field camera
"DSC06490.jpg" # Japanese garden steps "DSC06490.jpg" # Japanese garden steps
"DSC06687.jpg" # Multnomah Falls long exposure "DSC06687.jpg" # Multnomah Falls long exposure
"DSC06616.jpg" # B&W abstract
] ]
} }
} }

View File

@ -3,23 +3,37 @@ import * as R from "ramda";
import { graphql, Link } from "gatsby"; import { graphql, Link } from "gatsby";
import { navigate } from "gatsby"; import { navigate } from "gatsby";
import { Helmet } from "react-helmet"; import { Helmet } from "react-helmet";
import { Picker, Item } from "@adobe/react-spectrum";
import MasonryGallery from "../components/MasonryGallery"; import MasonryGallery from "../components/MasonryGallery";
const SORT_KEYS = {
hue: ["fields", "imageMeta", "vibrantHue"],
hue_debug: ["fields", "imageMeta", "dominantHue", 0],
date: [],
};
const GalleryPage = ({ data }) => { const GalleryPage = ({ data }) => {
const [debug, setDebug] = React.useState(false); const [sortKey, setSortKey] = React.useState("hue");
const images = React.useMemo( const images = React.useMemo(
() => () =>
R.pipe( R.pipe(
R.map((edge) => edge.node), R.map((edge) => edge.node),
debug sortKey === "date"
? R.sortBy(R.path(["fields", "imageMeta", "dominantHue", 0])) ? R.sort((node1, node2) => {
: R.sortBy(R.path(["fields", "imageMeta", "vibrantHue"])) const date1 = new Date(R.path(["fields", "imageMeta", "dateTaken"], node1));
const date2 = new Date(R.path(["fields", "imageMeta", "dateTaken"], node2));
return -1 * (date1.getTime() - date2.getTime())
})
: R.sortBy(R.path(SORT_KEYS[sortKey]))
)(data.allFile.edges), )(data.allFile.edges),
[data, debug] [data, sortKey]
); );
const showDebug = typeof window !== "undefined" &&
window.location.search.includes("debug=true")
return ( return (
<> <>
<Helmet> <Helmet>
@ -48,24 +62,23 @@ const GalleryPage = ({ data }) => {
</Link> </Link>
</nav> </nav>
<div className="bg-black min-h-screen mx-auto"> <div className="bg-black min-h-screen mx-auto">
<div className="flex flex-col md:flex-row"> <div className="flex flex-col sm:flex-row items-stretch sm:items-end">
<h1 className="text-5xl mt-0 ml-5 font-serif font-black z-10 flex-auto"> <h1 className="text-5xl mt-0 ml-5 font-serif font-black z-10 flex-auto">
Photo Gallery Photo Gallery
</h1> </h1>
{typeof window !== "undefined" && <div className="m-2 ml-5 self-end">
window.location.hash.includes("debug") ? ( <Picker
<div className="m-2"> label="Sort by..."
<label> onSelectionChange={setSortKey}
<input selectedKey={sortKey}
className="mr-1" >
onChange={() => setDebug(!debug)} <Item key="hue">Hue</Item>
type="checkbox" {showDebug && (
value={debug} <Item key="hue_debug">Dominant hue[debug]</Item>
/> )}
[debug] use stats.dominant instead of vibrant.Vibrant <Item key="date">Date</Item>
</label> </Picker>
</div> </div>
) : null}
</div> </div>
<div className="mx-auto"> <div className="mx-auto">
<MasonryGallery <MasonryGallery
@ -74,8 +87,9 @@ const GalleryPage = ({ data }) => {
md: 4, md: 4,
lg: 4, lg: 4,
xl: 5, xl: 5,
// '2xl': 6.1,
}} }}
debug={debug} debug={sortKey === 'hue_debug'}
images={images} images={images}
/> />
</div> </div>

1969
yarn.lock

File diff suppressed because it is too large Load Diff