Skip to content

Commit 20f506f

Browse files
committed
feat(Projects): add projects fetch
1 parent aae229a commit 20f506f

File tree

9 files changed

+220
-58
lines changed

9 files changed

+220
-58
lines changed

src/components/Buttons/ButtonGlow/ButtonGlow.js

-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import stylesBtn from '../Button/Button.module.scss';
22
import styles from './ButtonGlow.module.scss';
33
import CustomLink from '../../Link';
4-
import { useEffect } from 'react';
54

65
const ButtonGlow = ({ onClick, children, className, href, overglow, scroll, ...rest }) => {
7-
useEffect(() => {
8-
console.log('Rendering ButtonGlow');
9-
}, []);
106
const handleClick = (event) => {
117
event.preventDefault();
128
if (onClick) {

src/components/Slider/CardSlider/CardSlider.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ const CardSlider = ({ cards }) => {
116116
onClick={() => handleCardClick(index)}
117117
>
118118
<div className={styles['carousel-box']}>
119-
<div className={styles.title}>{card.title}</div>
119+
<div className={styles.title}>{card.name}</div>
120120
<div className={styles.num}>{String(index + 1).padStart(2, '0')}</div>
121-
<Image src={card.image} alt={card.title} width={200} height={400} />
121+
<Image src={card.thumbnail.url} alt={card.thumbnail.alt} width={200} height={400} />
122122
</div>
123123
</div>
124124
);
@@ -131,8 +131,8 @@ CardSlider.propTypes = {
131131
cards: PropTypes.arrayOf(
132132
PropTypes.shape({
133133
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
134-
title: PropTypes.string.isRequired,
135-
image: PropTypes.string.isRequired,
134+
name: PropTypes.string.isRequired,
135+
thumbnail: PropTypes.object.isRequired,
136136
}),
137137
).isRequired,
138138
};

src/components/Slider/CardSlider/CardSlider.module.css

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Slider/CardSlider/CardSlider.module.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Slider/CardSlider/CardSlider.module.scss

+5-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
height: 100%;
4545
transition: opacity 0.8s cubic-bezier(0, 0.02, 0, 1);
4646
opacity: var(--opacity);
47-
font-family: 'Orelo-sw-db', serif;
4847

4948
&:before {
5049
content: '';
@@ -71,18 +70,20 @@
7170
bottom: 20px;
7271
left: 20px;
7372
transition: opacity 0.8s cubic-bezier(0, 0.02, 0, 1);
74-
font-size: clamp(20px, 3vw, 30px);
73+
font-size: $font-size-h4;
74+
font-weight: bold;
7575
text-shadow: 04px 4px rgba(0, 0, 0, 0.1);
7676
}
7777

7878
.num {
7979
position: absolute;
8080
z-index: 1;
81-
color: #fff;
81+
color: $color-text-transparent-light;
8282
top: 10px;
8383
left: 20px;
8484
transition: opacity 0.8s cubic-bezier(0, 0.02, 0, 1);
85-
font-size: clamp(20px, 10vw, 80px);
85+
font-size: $font-size-h1;
86+
font-weight: bold;
8687
}
8788

8889
img {

src/data/customers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { gql } from '@apollo/client';
22

33
export const QUERY_ALL_CUSTOMERS = gql`
44
query AllCustomers {
5-
customers(where: { orderby: { field: DATE, order: ASC } }, first: 1000) {
5+
customers(where: { orderby: { field: DATE, order: ASC } }, first: 100) {
66
edges {
77
node {
88
id

src/data/projects.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { gql } from '@apollo/client';
2+
3+
export const QUERY_BEST_PROJECTS = gql`
4+
query BestProjects {
5+
projects(where: { orderby: { field: DATE, order: ASC } }, first: 10) {
6+
edges {
7+
node {
8+
id
9+
tags {
10+
nodes {
11+
name
12+
}
13+
}
14+
projectFieldGroup {
15+
name
16+
tags
17+
thumbnail {
18+
node {
19+
altText
20+
mediaItemUrl
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
}
28+
`;
29+
30+
export const QUERY_ALL_PROJECTS = gql`
31+
query BestProjects {
32+
projects(where: { orderby: { field: DATE, order: ASC } }, first: 100) {
33+
edges {
34+
node {
35+
id
36+
tags {
37+
nodes {
38+
name
39+
}
40+
}
41+
projectFieldGroup {
42+
name
43+
tags
44+
description
45+
url
46+
thumbnail {
47+
node {
48+
altText
49+
mediaItemUrl
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
`;

src/lib/projects.js

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import { getApolloClient } from 'lib/apollo-client';
2+
3+
import parameterize from 'parameterize';
4+
5+
import { QUERY_ALL_PROJECTS, QUERY_BEST_PROJECTS } from 'data/projects';
6+
7+
/**
8+
* projectPathBySlug
9+
*/
10+
11+
export function projectPathBySlug(slug) {
12+
return `/project/${slug}`;
13+
}
14+
15+
/**
16+
* getProjectBySlug
17+
*/
18+
19+
export async function getProjectBySlug(slug) {
20+
const { projects } = await getAllProjects();
21+
22+
const project = projects.find((project) => project.slug === slug);
23+
24+
return {
25+
project,
26+
};
27+
}
28+
29+
/**
30+
* projectPathByName
31+
*/
32+
33+
export function projectPathByName(name) {
34+
return `/project/${parameterize(name)}`;
35+
}
36+
37+
/**
38+
* getCustomerByNameSlug
39+
*/
40+
41+
export async function getProjectByNameSlug(name) {
42+
const { projects } = await getAllProjects();
43+
44+
const project = projects.find((project) => parameterize(project.name) === name);
45+
46+
return {
47+
project,
48+
};
49+
}
50+
51+
/**
52+
* projectSlugByName
53+
*/
54+
55+
export function projectSlugByName(name) {
56+
return parameterize(name);
57+
}
58+
59+
/**
60+
* getAllProjects
61+
*/
62+
63+
export async function getAllProjects() {
64+
const apolloClient = getApolloClient();
65+
66+
let projectsData;
67+
68+
try {
69+
projectsData = await apolloClient.query({
70+
query: QUERY_ALL_PROJECTS,
71+
});
72+
} catch (e) {
73+
console.log(`[projects][getAllProjects] Failed to query project data: ${e.message}`);
74+
throw e;
75+
}
76+
77+
let projects = projectsData?.data.projects.edges.map(({ node = {} }) => node).map(mapProjectData);
78+
79+
return {
80+
projects,
81+
};
82+
}
83+
84+
/**
85+
* getBestProjects
86+
*/
87+
export async function getBestProjects() {
88+
const apolloClient = getApolloClient();
89+
90+
let projectsData;
91+
92+
try {
93+
projectsData = await apolloClient.query({
94+
query: QUERY_BEST_PROJECTS,
95+
});
96+
} catch (e) {
97+
console.log(`[projects][getBestProjects] Failed to query project data: ${e.message}`);
98+
throw e;
99+
}
100+
let projects = projectsData?.data.projects.edges.map(({ node = {} }) => node).map(mapBestProjectData);
101+
102+
return {
103+
projects,
104+
};
105+
}
106+
107+
/**
108+
* mapProjectData
109+
*/
110+
111+
export function mapProjectData(project) {
112+
const { id, tags, projectFieldGroup } = project;
113+
return {
114+
id,
115+
name: projectFieldGroup?.name || '',
116+
description: projectFieldGroup?.description || '',
117+
tags: tags?.nodes?.map((tag) => tag.name) || [],
118+
liveDemo: projectFieldGroup?.url || '',
119+
thumbnail: {
120+
alt: projectFieldGroup?.thumbnail?.node.altText || '',
121+
url: projectFieldGroup?.thumbnail?.node.mediaItemUrl || '',
122+
},
123+
};
124+
}
125+
126+
/**
127+
* mapProjectData
128+
*/
129+
130+
export function mapBestProjectData(project) {
131+
const { id, tags, projectFieldGroup } = project;
132+
return {
133+
id,
134+
name: projectFieldGroup?.name || '',
135+
tags: tags?.nodes?.map((tag) => tag.name) || [],
136+
liveDemo: projectFieldGroup?.url || '',
137+
thumbnail: {
138+
alt: projectFieldGroup?.thumbnail?.node.altText || '',
139+
url: projectFieldGroup?.thumbnail?.node.mediaItemUrl || '',
140+
},
141+
};
142+
}

src/pages/home.js

+5-40
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,15 @@ import Button from '../components/Buttons/Button';
1818
import { IoArchiveOutline, IoMailUnreadOutline } from 'react-icons/io5';
1919
import CardSlider from '../components/Slider/CardSlider';
2020
import GradientText from '../components/Text/GradientText';
21+
import { getBestProjects } from '../lib/projects';
2122

22-
export default function Home({ customers }) {
23+
export default function Home({ customers, bestProjects }) {
2324
const { metadata = {} } = useSite();
2425
const { title } = metadata;
2526
const { isMobile } = useViewport();
2627
const { setCameraTarget } = useContext(ThreeSceneContext);
2728
const clientsRef = useRef(null);
2829
const currentYear = new Date().getFullYear();
29-
const projectCards = [
30-
{
31-
id: 1,
32-
title: 'Paris',
33-
image:
34-
'https://media.istockphoto.com/id/184619832/it/foto/distretto-finanziario-al-crepuscolo-londra.jpg?s=612x612&w=0&k=20&c=RAThrJOBY6vhlT6-kQpu9-9jLEzWToYfdw46S8B0Mu0=',
35-
},
36-
{
37-
id: 2,
38-
title: 'Warsaw',
39-
image:
40-
'https://media.istockphoto.com/id/184619832/it/foto/distretto-finanziario-al-crepuscolo-londra.jpg?s=612x612&w=0&k=20&c=RAThrJOBY6vhlT6-kQpu9-9jLEzWToYfdw46S8B0Mu0=',
41-
},
42-
{
43-
id: 3,
44-
title: 'Madrid',
45-
image:
46-
'https://media.istockphoto.com/id/184619832/it/foto/distretto-finanziario-al-crepuscolo-londra.jpg?s=612x612&w=0&k=20&c=RAThrJOBY6vhlT6-kQpu9-9jLEzWToYfdw46S8B0Mu0=',
47-
},
48-
{
49-
id: 4,
50-
title: 'Sydney',
51-
image:
52-
'https://media.istockphoto.com/id/184619832/it/foto/distretto-finanziario-al-crepuscolo-londra.jpg?s=612x612&w=0&k=20&c=RAThrJOBY6vhlT6-kQpu9-9jLEzWToYfdw46S8B0Mu0=',
53-
},
54-
{
55-
id: 5,
56-
title: 'Istanbul',
57-
image:
58-
'https://media.istockphoto.com/id/184619832/it/foto/distretto-finanziario-al-crepuscolo-londra.jpg?s=612x612&w=0&k=20&c=RAThrJOBY6vhlT6-kQpu9-9jLEzWToYfdw46S8B0Mu0=',
59-
},
60-
{
61-
id: 6,
62-
title: 'Prague',
63-
image:
64-
'https://media.istockphoto.com/id/184619832/it/foto/distretto-finanziario-al-crepuscolo-londra.jpg?s=612x612&w=0&k=20&c=RAThrJOBY6vhlT6-kQpu9-9jLEzWToYfdw46S8B0Mu0=',
65-
},
66-
];
6730

6831
useEffect(() => {
6932
const newTarget = new Vector3();
@@ -142,7 +105,7 @@ export default function Home({ customers }) {
142105
</Section>
143106
<Section className={styles.portfolioSection}>
144107
<Content className={styles.portfolioContent}>
145-
<CardSlider className={styles.cardSlider} cards={projectCards} />
108+
<CardSlider cards={bestProjects} />
146109
<div className={styles.portfolioTextBlock}>
147110
<h3>My Projects</h3>
148111
<p>
@@ -174,9 +137,11 @@ export default function Home({ customers }) {
174137

175138
export async function getStaticProps() {
176139
const { customers } = await getAllCustomers();
140+
const { projects: bestProjects = [] } = await getBestProjects();
177141
return {
178142
props: {
179143
customers,
144+
bestProjects,
180145
},
181146
};
182147
}

0 commit comments

Comments
 (0)