Skip to content

Commit 356981f

Browse files
committed
Extract edges and boxes out from the components.
1 parent b029d64 commit 356981f

File tree

2 files changed

+96
-61
lines changed

2 files changed

+96
-61
lines changed

src/components/index-page/data-colocation/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import {
1111
import { Pre } from "@/components/pre"
1212
import { SectionLabel } from "@/app/conf/_design-system/section-label"
1313
import InfoIcon from "@/app/conf/_design-system/pixelarticons/info.svg?svgr"
14+
import { useOnClickOutside } from "@/app/conf/_design-system/utils/useOnClickOutside"
15+
import { isSpanElement } from "@/app/conf/_design-system/utils/isSpanElement"
1416

1517
import { ComponentTree } from "./component-tree"
1618
import { FriendList } from "./friend-list"
1719

1820
import json from "./data-colocation.json"
1921
import Query from "./data-colocation.mdx"
2022
import "./data-colocation.css"
21-
import { useOnClickOutside } from "@/app/conf/_design-system/utils/useOnClickOutside"
22-
import { isSpanElement } from "@/app/conf/_design-system/utils/isSpanElement"
2323

2424
const highlightedFragments = {
2525
GetFriendList: 1,

src/components/index-page/what-is-graphql/wires.tsx

Lines changed: 94 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
useReducer,
99
useRef,
1010
} from "react"
11+
import { throttle } from "@/app/conf/_design-system/utils/throttle"
1112

1213
import { Code } from "nextra/components"
1314

@@ -27,32 +28,33 @@ import {
2728
import QueryMdx from "./api-gateway-query.mdx"
2829
import ResponseMdx from "./api-gateway-response.mdx"
2930
import styles from "./wires.module.css"
30-
import { throttle } from "@/app/conf/_design-system/utils/throttle"
31+
32+
const bigScreenClientEdges = [
33+
"M514.5 220H424.5V76H72",
34+
"M446 220H424.5V112H144",
35+
"M446 220H424.5V147H72",
36+
"M446 220H424.5V184H144",
37+
"M528 220H514.206L72 220",
38+
"M528 220L424.866 220V256H144",
39+
"M446 220L424.5 220V291.75H72",
40+
"M528.5 220H424.5V328H144",
41+
"M528 220H424.772V365H72",
42+
]
3143

3244
function ClientEdges({
3345
highlightedEdge,
3446
highlightedVisible,
47+
edges,
3548
}: {
3649
highlightedEdge?: number
3750
highlightedVisible: boolean
51+
edges: string[]
3852
}) {
39-
const paths = [
40-
"M514.5 220H424.5V76H72",
41-
"M446 220H424.5V112H144",
42-
"M446 220H424.5V147H72",
43-
"M446 220H424.5V184H144",
44-
"M528 220H514.206L72 220",
45-
"M528 220L424.866 220V256H144",
46-
"M446 220L424.5 220V291.75H72",
47-
"M528.5 220H424.5V328H144",
48-
"M528 220H424.772V365H72",
49-
]
50-
5153
return (
5254
<>
5355
{moveHighlightedToTop(
5456
highlightedEdge,
55-
paths.map((path, index) => (
57+
edges.map((path, index) => (
5658
<Fragment key={index}>
5759
<path
5860
d={path}
@@ -74,28 +76,30 @@ function ClientEdges({
7476
)
7577
}
7678

79+
const bigScreenServerEdges = [
80+
"M696 159.5H811.5V75H1176",
81+
"M696 175.5L833.5 175.5V112H1104.5",
82+
"M696 191.5H855.5V148.5H1176",
83+
"M696 206.5L876 206.5V184.5H1104",
84+
"M696 220.5H704.5H1176",
85+
"M696 234.5L876 234.5V256.5H1104",
86+
"M696 249.5H855.5V292.5H1176",
87+
"M696 265.5L833.5 265.5V329H1104",
88+
"M696 281.5H811.5V366H1176",
89+
]
90+
7791
function ServerEdges({
7892
highlighted,
7993
highlightedVisible,
94+
edges,
8095
}: {
8196
highlighted: number[]
8297
highlightedVisible: boolean
98+
edges: string[]
8399
}) {
84-
const paths = [
85-
"M696 159.5H811.5V75H1176",
86-
"M696 175.5L833.5 175.5V112H1104.5",
87-
"M696 191.5H855.5V148.5H1176",
88-
"M696 206.5L876 206.5V184.5H1104",
89-
"M696 220.5H704.5H1176",
90-
"M696 234.5L876 234.5V256.5H1104",
91-
"M696 249.5H855.5V292.5H1176",
92-
"M696 265.5L833.5 265.5V329H1104",
93-
"M696 281.5H811.5V366H1176",
94-
] as const
95-
96100
return (
97101
<>
98-
{paths.map((d, index) => {
102+
{edges.map((d, index) => {
99103
const isHighlighted = highlighted?.includes(index)
100104
return (
101105
<Fragment key={index}>
@@ -147,21 +151,27 @@ function Box({
147151
)
148152
}
149153

150-
function ClientBoxes({ highlighted }: { highlighted?: number }) {
151-
/* eslint-disable react/jsx-key */
152-
const boxes = [
153-
["translate(16, 48)", <DesktopIcon />],
154-
["translate(88, 84)", <PhoneIcon />],
155-
["translate(16, 120)", <PhoneIcon />],
156-
["translate(88, 156)", <WristwatchIcon />],
157-
["translate(16, 192)", <TelevisionIcon />],
158-
["translate(88, 228)", <DesktopIcon />],
159-
["translate(16, 264)", <TabletIcon />],
160-
["translate(88, 300)", <PhoneIcon />],
161-
["translate(16, 336)", <WristwatchIcon />],
162-
] as const
163-
/* eslint-enable react/jsx-key */
154+
/* eslint-disable react/jsx-key */
155+
const bigScreenClientBoxes: Array<[string, React.ReactNode]> = [
156+
["translate(16, 48)", <DesktopIcon />],
157+
["translate(88, 84)", <PhoneIcon />],
158+
["translate(16, 120)", <PhoneIcon />],
159+
["translate(88, 156)", <WristwatchIcon />],
160+
["translate(16, 192)", <TelevisionIcon />],
161+
["translate(88, 228)", <DesktopIcon />],
162+
["translate(16, 264)", <TabletIcon />],
163+
["translate(88, 300)", <PhoneIcon />],
164+
["translate(16, 336)", <WristwatchIcon />],
165+
]
166+
/* eslint-enable react/jsx-key */
164167

168+
function ClientBoxes({
169+
highlighted,
170+
boxes,
171+
}: {
172+
highlighted?: number
173+
boxes: Array<[string, React.ReactNode]>
174+
}) {
165175
return (
166176
<>
167177
{boxes.map(([transform, children], index) => {
@@ -184,21 +194,27 @@ function ClientBoxes({ highlighted }: { highlighted?: number }) {
184194
)
185195
}
186196

187-
function ServerBoxes({ highlighted }: { highlighted: number[] }) {
188-
/* eslint-disable react/jsx-key */
189-
const boxes = [
190-
["translate(1176, 48)", <LabirynthIcon />],
191-
["translate(1104, 84)", <ServerIcon />],
192-
["translate(1176, 120)", <ModemIcon />],
193-
["translate(1104, 156)", <CloudIcon />],
194-
["translate(1176, 192)", <LabirynthIcon />],
195-
["translate(1104, 228)", <ModemIcon />],
196-
["translate(1176, 264)", <CloudIcon />],
197-
["translate(1104, 300)", <CloudIcon />],
198-
["translate(1176, 336)", <ServerIcon />],
199-
] as const
200-
/* eslint-enable react/jsx-key */
197+
/* eslint-disable react/jsx-key */
198+
const bigScreenServerBoxes: Array<[string, React.ReactNode]> = [
199+
["translate(1176, 48)", <LabirynthIcon />],
200+
["translate(1104, 84)", <ServerIcon />],
201+
["translate(1176, 120)", <ModemIcon />],
202+
["translate(1104, 156)", <CloudIcon />],
203+
["translate(1176, 192)", <LabirynthIcon />],
204+
["translate(1104, 228)", <ModemIcon />],
205+
["translate(1176, 264)", <CloudIcon />],
206+
["translate(1104, 300)", <CloudIcon />],
207+
["translate(1176, 336)", <ServerIcon />],
208+
]
209+
/* eslint-enable react/jsx-key */
201210

211+
function ServerBoxes({
212+
highlighted,
213+
boxes,
214+
}: {
215+
highlighted: number[]
216+
boxes: Array<[string, React.ReactNode]>
217+
}) {
202218
return (
203219
<>
204220
{boxes.map(([transform, children], index) => {
@@ -520,6 +536,7 @@ export function Wires({ className }: { className?: string }) {
520536
styles.wires,
521537
)}
522538
>
539+
<MobileDiagram />
523540
<svg
524541
id="what-is-graphql--wires"
525542
width="1248"
@@ -531,10 +548,24 @@ export function Wires({ className }: { className?: string }) {
531548
className="relative h-auto w-full"
532549
ref={ref}
533550
>
534-
<ClientEdges highlightedEdge={0} highlightedVisible={step === 0} />
535-
<ClientBoxes highlighted={step === 0 ? 0 : undefined} />
536-
<ServerEdges highlighted={[1, 6]} highlightedVisible={step > 0} />
537-
<ServerBoxes highlighted={step > 0 ? [1, 6] : []} />
551+
<ClientEdges
552+
highlightedEdge={0}
553+
highlightedVisible={step === 0}
554+
edges={bigScreenClientEdges}
555+
/>
556+
<ClientBoxes
557+
highlighted={step === 0 ? 0 : undefined}
558+
boxes={bigScreenClientBoxes}
559+
/>
560+
<ServerEdges
561+
highlighted={[1, 6]}
562+
highlightedVisible={step > 0}
563+
edges={bigScreenServerEdges}
564+
/>
565+
<ServerBoxes
566+
highlighted={step > 0 ? [1, 6] : []}
567+
boxes={bigScreenServerBoxes}
568+
/>
538569
<SVGDefinitions />
539570
</svg>
540571
<button
@@ -602,3 +633,7 @@ function Curtain() {
602633
/>
603634
)
604635
}
636+
637+
function MobileDiagram() {
638+
return <svg>{/* HERE */}</svg>
639+
}

0 commit comments

Comments
 (0)