Skip to content

Commit

Permalink
prismic
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesvinckier committed Oct 5, 2023
1 parent c8d50f4 commit 8b6d6f3
Show file tree
Hide file tree
Showing 25 changed files with 402 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules/
.cache/
public
.DS_Store
yarn-error.log
.env*
31 changes: 31 additions & 0 deletions custom_types/works.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"Main": {
"uid": {
"type": "UID",
"config": {
"label": "slug"
}
},
"title": {
"type": "StructuredText",
"config": {
"single": "heading1,heading2,heading3,heading4,heading5,heading6",
"label": "title"
}
},
"cover": {
"type": "Image",
"config": {
"constraint": {},
"thumbnails": [],
"label": "cover"
}
},
"description": {
"type": "Text",
"config": {
"label": "description"
}
}
}
}
36 changes: 27 additions & 9 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,32 @@
module.exports = {
siteMetadata: {
title: `r3f caroussel`,
siteUrl: `https://www.yourdomain.tld`
siteUrl: `https://www.yourdomain.tld`,
},
plugins: ["gatsby-plugin-emotion", "gatsby-plugin-image", "gatsby-plugin-sitemap", "gatsby-plugin-sharp", "gatsby-transformer-sharp", {
resolve: 'gatsby-source-filesystem',
options: {
"name": "images",
"path": "./src/images/"
plugins: [
"gatsby-plugin-emotion",
"gatsby-plugin-image",
"gatsby-plugin-sitemap",
"gatsby-plugin-sharp",
"gatsby-transformer-sharp",
"gatsby-plugin-transition-link",
{
resolve: "gatsby-source-filesystem",
options: {
name: "images",
path: "./src/images/",
},
__key: "images",
},
__key: "images"
}]
};
{
resolve: "gatsby-source-prismic",
accessToken: `${process.env.API_KEY}`,
options: {
repositoryName: "r3f-caroussel",
schemas: {
works: require("./custom_types/works.json"),
},
},
},
],
};
1 change: 1 addition & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.createPages = require("./src/gatsby/node/createPages");
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"gatsby-plugin-image": "^3.12.0",
"gatsby-plugin-sharp": "^5.12.0",
"gatsby-plugin-sitemap": "^6.12.0",
"gatsby-plugin-transition-link": "^1.20.5",
"gatsby-source-filesystem": "^5.12.0",
"gatsby-source-prismic": "^6.0.1",
"gatsby-transformer-sharp": "^5.12.0",
"gsap": "^3.12.2",
"leva": "^0.9.35",
Expand Down
21 changes: 21 additions & 0 deletions src/gatsby/data/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports.data = {
works: `{
allPrismicWorks(sort: {first_publication_date: DESC}) {
edges {
node {
uid
data {
cover {
gatsbyImageData
alt
}
title {
text
}
description
}
}
}
}
}`,
};
24 changes: 24 additions & 0 deletions src/gatsby/node/createPages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const query = require("../data/query");
const path = require(`path`);

module.exports = async ({ graphql, actions }) => {
const { createPage } = actions;

// Create a page for each post
const worksQuery = await graphql(query.data.works);
const works = worksQuery.data.allPrismicWorks.edges;
works.forEach((work, i) => {
const selected = work.node;
const previous = i === works.length - 1 ? null : works[i + 1].node;
const next = i === 0 ? null : works[i - 1].node;
createPage({
path: `/${work.node.uid}/`,
component: path.resolve(`./src/templates/work.js`),
context: {
...selected,
previous,
next,
},
});
});
};
28 changes: 26 additions & 2 deletions src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
import React, { Suspense } from "react";
import { Canvas } from "@react-three/fiber";
import { graphql } from "gatsby";

import Carousel from "../three/Carousel";
import "../style/styles.css";

const IndexPage = () => {
const IndexPage = ({ data }) => {
const works = data.allPrismicWorks.edges;
return (
<>
<Suspense fallback={null}>
<Canvas>
<Carousel />
<Carousel works={works} />
</Canvas>
</Suspense>
</>
);
};

export const query = graphql`
query {
allPrismicWorks(sort: { first_publication_date: DESC }) {
edges {
node {
uid
data {
cover {
gatsbyImageData(width: 1800, placeholder: BLURRED)
alt
}
title {
text
}
description
}
}
}
}
}
`;

export default IndexPage;

export const Head = () => <title>Home Page</title>;
14 changes: 14 additions & 0 deletions src/templates/work.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";

const work = ({ pageContext }) => {
const { title, cover, description } = pageContext.data;
const { next } = pageContext;

return (
<>
<div>{title.text}</div>
</>
);
};

export default work;
28 changes: 15 additions & 13 deletions src/three/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { useEffect, useRef, useState, useMemo } from "react";
import { useFrame, useThree } from "@react-three/fiber";
import { usePrevious } from "react-use";
import gsap from "gsap";

import CarouselItem from "./CarouselItem";
import images from "../data/images";

/*------------------------------
Plane Settings
Expand All @@ -25,7 +25,7 @@ gsap.defaults({
/*------------------------------
Carousel
------------------------------*/
const Carousel = () => {
const Carousel = ({ works }) => {
const [root, setRoot] = useState();

const [activePlane, setActivePlane] = useState(null);
Expand All @@ -40,15 +40,15 @@ const Carousel = () => {
const isDown = useRef(false);
const speedWheel = 0.02;
const speedDrag = -0.3;
const items = useMemo(() => {
const images = useMemo(() => {
if (root) return root.children;
}, [root]);

/*--------------------
Diaplay Items
--------------------*/
const displayItems = (item, index, active) => {
gsap.to(item.position, {
const displayItems = (image, index, active) => {
gsap.to(image.position, {
x: (index - active) * (planeSettings.width + planeSettings.gap),
y: 0,
});
Expand All @@ -60,8 +60,8 @@ const Carousel = () => {
useFrame(() => {
progress.current = Math.max(0, Math.min(progress.current, 100));

const active = Math.floor((progress.current / 100) * (items.length - 1));
items.forEach((item, index) => displayItems(item, index, active));
const active = Math.floor((progress.current / 100) * (images.length - 1));
images.forEach((image, index) => displayItems(image, index, active));
});

/*--------------------
Expand Down Expand Up @@ -105,11 +105,11 @@ const Carousel = () => {
Click
--------------------*/
useEffect(() => {
if (!items) return;
if (!images) return;
if (activePlane !== null && prevActivePlane === null) {
progress.current = (activePlane / (items.length - 1)) * 100; // Calculate the progress.current based on activePlane
progress.current = (activePlane / (images.length - 1)) * 100; // Calculate the progress.current based on activePlane
}
}, [activePlane, items, prevActivePlane]);
}, [activePlane, images, prevActivePlane]);

/*--------------------
Render Plane Events
Expand Down Expand Up @@ -137,15 +137,17 @@ const Carousel = () => {
const renderSlider = () => {
return (
<group ref={setRoot}>
{images.map((item, i) => (
{works.map(({ node: work }, i) => (
<CarouselItem
width={planeSettings.width}
height={planeSettings.height}
setActivePlane={setActivePlane}
activePlane={activePlane}
key={item.image}
item={item}
key={i}
image={work.data.cover.gatsbyImageData}
index={i}
works={works}
slug={`/${work.uid}/`}
/>
))}
</group>
Expand Down
9 changes: 7 additions & 2 deletions src/three/CarouselItem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useEffect, useRef, useState } from "react";
import { useThree } from "@react-three/fiber";
import { navigate } from "gatsby";
import { getSrc } from "gatsby-plugin-image";
import gsap from "gsap";
import Plane from "./Plane";

Expand All @@ -9,14 +11,16 @@ const CarouselItem = ({
height,
setActivePlane,
activePlane,
item,
image,
slug,
}) => {
const groupRef = useRef();
const [hover, setHover] = useState(false);
const [isActive, setIsActive] = useState(false);
const [isCloseActive, setCloseActive] = useState(false);
const { viewport } = useThree();
const timeoutID = useRef();
const imageSrc = getSrc(image);

useEffect(() => {
if (activePlane === index) {
Expand Down Expand Up @@ -66,14 +70,15 @@ const CarouselItem = ({
ref={groupRef}
onClick={() => {
setActivePlane(index);
navigate(slug);
}}
onPointerEnter={() => setHover(true)}
onPointerLeave={() => setHover(false)}
>
<Plane
width={width}
height={height}
texture={item.image}
texture={imageSrc}
active={isActive}
/>

Expand Down
Binary file removed static/.DS_Store
Binary file not shown.
Binary file removed static/1.jpg
Binary file not shown.
Binary file removed static/10.jpg
Binary file not shown.
Binary file removed static/11.jpg
Binary file not shown.
Binary file removed static/12.jpg
Binary file not shown.
Binary file removed static/2.jpg
Binary file not shown.
Binary file removed static/3.jpg
Binary file not shown.
Binary file removed static/4.jpg
Binary file not shown.
Binary file removed static/5.jpg
Binary file not shown.
Binary file removed static/6.jpg
Binary file not shown.
Binary file removed static/7.jpg
Binary file not shown.
Binary file removed static/8.jpg
Binary file not shown.
Binary file removed static/9.jpg
Binary file not shown.
Loading

0 comments on commit 8b6d6f3

Please sign in to comment.