Skip to content

Commit 4af3f75

Browse files
committedAug 14, 2024·
feat(): add customer api request for logo slider
1 parent b23f53d commit 4af3f75

17 files changed

+245
-12
lines changed
 

‎.husky/pre-commit

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
#! /bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
3-
4-
# Dein neuer Befehl hier
51
pnpm lint-staged

‎public/images/logos/customers/Logo-ASMS.svg

-1
This file was deleted.

‎public/images/logos/customers/Logo-CD.svg

-1
This file was deleted.

‎public/images/logos/customers/Logo-HdM.svg

-1
This file was deleted.

‎public/images/logos/customers/Logo-Kanzlei-Lang.svg

-1
This file was deleted.

‎public/images/logos/customers/Logo-Med-Dent-Consult.svg

-1
This file was deleted.

‎public/images/logos/customers/Logo-Praxis-Lang.svg

-1
This file was deleted.

‎public/images/logos/customers/Logo-Zoopra.svg

-1
This file was deleted.

‎src/components/Sections/Header/Header.module.scss

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@import '../../../styles/settings/_settings';
22

33
.header {
4+
position: fixed;
5+
z-index: 1;
46
display: flex;
57
justify-content: space-between;
68
align-items: center;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import styles from './LogoSlider.module.scss';
2+
3+
const LogoSlider = ({ children }) => {
4+
return <div className={styles.container}>{children}</div>;
5+
};
6+
7+
export default LogoSlider;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import '../../../styles/settings/__settings';
2+
3+
.container {
4+
display: flex;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './LogoSlider';

‎src/data/customers.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { gql } from '@apollo/client';
2+
3+
export const QUERY_ALL_CUSTOMERS = gql`
4+
query AllCustomers {
5+
customers(where: { orderby: { field: DATE, order: ASC } }, first: 1000) {
6+
edges {
7+
node {
8+
id
9+
customerFieldGroup {
10+
customerName
11+
customerPage
12+
customerLogo {
13+
node {
14+
altText
15+
mediaItemUrl
16+
}
17+
}
18+
}
19+
}
20+
}
21+
}
22+
}
23+
`;
24+
25+
export const QUERY_ALL_CUSTOMERS_SEO = gql`
26+
query AllCustomers {
27+
customers(first: 100, where: { orderby: { field: DATE, order: ASC } }) {
28+
nodes {
29+
id
30+
seo {
31+
metaDesc
32+
metaRobotsNofollow
33+
metaRobotsNoindex
34+
title
35+
social {
36+
youTube
37+
wikipedia
38+
twitter
39+
soundCloud
40+
pinterest
41+
mySpace
42+
linkedIn
43+
instagram
44+
facebook
45+
}
46+
}
47+
}
48+
}
49+
}
50+
`;

‎src/lib/customers.js

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { getApolloClient } from 'lib/apollo-client';
2+
3+
import parameterize from 'parameterize';
4+
5+
import { QUERY_ALL_CUSTOMERS, QUERY_ALL_CUSTOMERS_SEO } from 'data/customers';
6+
7+
/**
8+
* customerPathBySlug
9+
*/
10+
11+
export function customerPathBySlug(slug) {
12+
return `/customer/${slug}`;
13+
}
14+
15+
/**
16+
* getCustomerBySlug
17+
*/
18+
19+
export async function getCustomerBySlug(slug) {
20+
const { customers } = await getAllCustomers();
21+
22+
const customer = customers.find((customer) => customer.slug === slug);
23+
24+
return {
25+
customer,
26+
};
27+
}
28+
29+
/**
30+
* customerPathByName
31+
*/
32+
33+
export function customerPathByName(name) {
34+
return `/customer/${parameterize(name)}`;
35+
}
36+
37+
/**
38+
* getCustomerByNameSlug
39+
*/
40+
41+
export async function getCustomerByNameSlug(name) {
42+
const { customers } = await getAllCustomers();
43+
44+
const customer = customers.find((customer) => parameterize(customer.name) === name);
45+
46+
return {
47+
customer,
48+
};
49+
}
50+
51+
/**
52+
* customerSlugByName
53+
*/
54+
55+
export function customerSlugByName(name) {
56+
return parameterize(name);
57+
}
58+
59+
/**
60+
* getAllCustomers
61+
*/
62+
63+
export async function getAllCustomers() {
64+
const apolloClient = getApolloClient();
65+
66+
let customerData;
67+
let seoData;
68+
69+
try {
70+
customerData = await apolloClient.query({
71+
query: QUERY_ALL_CUSTOMERS,
72+
});
73+
} catch (e) {
74+
console.log(`[customers][getAllCustomers] Failed to query customer data: ${e.message}`);
75+
throw e;
76+
}
77+
78+
let customers = customerData?.data.customers.edges.map(({ node = {} }) => node).map(mapCustomerData);
79+
80+
// If the SEO plugin is enabled, look up the data
81+
// and apply it to the default settings
82+
83+
if (process.env.WORDPRESS_PLUGIN_SEO === true) {
84+
try {
85+
seoData = await apolloClient.query({
86+
query: QUERY_ALL_CUSTOMERS_SEO,
87+
});
88+
} catch (e) {
89+
console.log(`[customers][getAllCustomers] Failed to query SEO plugin: ${e.message}`);
90+
console.log('Is the SEO Plugin installed? If not, disable WORDPRESS_PLUGIN_SEO in next.config.js.');
91+
throw e;
92+
}
93+
94+
customers = customers.map((customer) => {
95+
const data = { ...customer };
96+
const { id } = data;
97+
98+
const seo = seoData?.data?.customers.edges.map(({ node = {} }) => node).find((node) => node.id === id)?.seo;
99+
100+
return {
101+
...data,
102+
title: seo.title,
103+
description: seo.metaDesc,
104+
robots: {
105+
nofollow: seo.metaRobotsNofollow,
106+
noindex: seo.metaRobotsNoindex,
107+
},
108+
social: seo.social,
109+
};
110+
});
111+
}
112+
113+
return {
114+
customers,
115+
};
116+
}
117+
118+
/**
119+
* mapCustomerData
120+
*/
121+
122+
export function mapCustomerData(customer) {
123+
const { id, customerFieldGroup } = customer;
124+
return {
125+
id,
126+
name: customerFieldGroup?.customerName || '',
127+
site: customerFieldGroup?.customerPage || '',
128+
logo: {
129+
alt: customerFieldGroup?.customerLogo?.node.altText || '',
130+
url: customerFieldGroup?.customerLogo?.node.mediaItemUrl || '',
131+
},
132+
};
133+
}
134+
135+
/**
136+
* updateCustomerAvatar
137+
*/
138+
139+
export function updateCustomerAvatar(avatar) {
140+
// The URL by default that comes from Gravatar / WordPress is not a secure
141+
// URL. This ends up redirecting to https, but it gives mixed content warnings
142+
// as the HTML shows it as http. Replace the url to avoid those warnings
143+
// and provide a secure URL by default
144+
145+
return {
146+
...avatar,
147+
url: avatar.url?.replace('http://', 'https://'),
148+
};
149+
}

‎src/pages/home.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ import { ThreeSceneContext } from '../components/3D/ThreeSceneProvider';
1313
import { Vector3 } from 'three';
1414
import { useViewport } from '../components/_General/Viewport/ViewportProvider';
1515
import Hero from '../components/Sections/Heros/Hero';
16+
import LogoSlider from '../components/Slider/LogoSlider';
17+
import Image from 'next/image';
18+
import CustomLink from '../components/Link';
19+
import { getAllCustomers } from '../lib/customers';
1620

17-
export default function Home({ posts, pagination }) {
21+
export default function Home({ posts, pagination, customers }) {
1822
const { metadata = {} } = useSite();
1923
const { title } = metadata;
2024
const { isMobile } = useViewport();
@@ -34,6 +38,17 @@ export default function Home({ posts, pagination }) {
3438
<Layout>
3539
<WebsiteJsonLd siteTitle={title} />
3640
<Hero />
41+
<LogoSlider>
42+
{customers.map((customer) => {
43+
return (
44+
<CustomLink key={customer.id} href={customer.site} className={styles.customerLink}>
45+
<div className={styles.customerLogo}>
46+
<Image src={customer.logo.url} alt={customer.logo.alt} width={53} height={33} />
47+
</div>
48+
</CustomLink>
49+
);
50+
})}
51+
</LogoSlider>
3752
<Section>
3853
<Container>
3954
<h2 className="sr-only">Posts</h2>
@@ -64,8 +79,11 @@ export async function getStaticProps() {
6479
const { posts, pagination } = await getPaginatedPosts({
6580
queryIncludes: 'archive',
6681
});
82+
const { customers } = await getAllCustomers();
83+
console.log(customers);
6784
return {
6885
props: {
86+
customers,
6987
posts,
7088
pagination: {
7189
...pagination,

‎src/pages/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ import Modal from '../components/Modal';
88
import OSXWindow from '../components/ContainerElements/OSXWindow';
99
import Terminal from '../components/Terminal';
1010
import { useRouter } from 'next/router';
11+
import { ThreeSceneContext } from '../components/3D/ThreeSceneProvider';
12+
import { Vector3 } from 'three';
1113

1214
export default function Start() {
1315
const { playSound, stopSound } = useContext(AudioContext);
1416
const [shape, setShape] = useState('sphere');
1517
const [isModalVisible, setModalVisible] = useState(false);
1618
const [terminalChildren, setTerminalChildren] = useState(null);
1719
const router = useRouter();
20+
const { setCameraTarget } = useContext(ThreeSceneContext);
21+
22+
useEffect(() => {
23+
setCameraTarget(new Vector3());
24+
}, [setCameraTarget]);
1825

1926
const changeParticles = useCallback(() => {
2027
setShape(shape === 'sphere' ? 'cube' : 'sphere');

‎src/styles/pages/Home.module.scss

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
@import '../../styles/settings/__settings';
22

3+
.customerLogo {
4+
width: auto;
5+
height: 10vh;
6+
}
7+
38
.description {
49
text-align: center;
510
line-height: 1.5;

0 commit comments

Comments
 (0)
Please sign in to comment.