Skip to content

Commit 67b8ee1

Browse files
committed
fix: server to client animation
1 parent f32f135 commit 67b8ee1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/components/EncapsulatedPacket.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function EncapsulatedPacket(props: Props) {
1919
}, [props.stage])
2020

2121
const currentPosition = useMemo(() => {
22+
const fromClient = props.packet.from === 'client'
2223
const CLIENT_X = 20
2324
const SERVER_X = 80
2425
const TRANSMISSION_X = 50
@@ -27,19 +28,19 @@ function EncapsulatedPacket(props: Props) {
2728
const STEP_Y = SPACING * 20
2829

2930
const positions = [
30-
{ x: CLIENT_X, y: START_Y }, // Application
31-
{ x: CLIENT_X, y: START_Y + STEP_Y }, // Transport
32-
{ x: CLIENT_X, y: START_Y + STEP_Y * 2 }, // Internet
33-
{ x: CLIENT_X, y: START_Y + STEP_Y * 3 }, // Network Interface
31+
{ x: fromClient ? CLIENT_X : SERVER_X, y: START_Y }, // Application
32+
{ x: fromClient ? CLIENT_X : SERVER_X, y: START_Y + STEP_Y }, // Transport
33+
{ x: fromClient ? CLIENT_X : SERVER_X, y: START_Y + STEP_Y * 2 }, // Internet
34+
{ x: fromClient ? CLIENT_X : SERVER_X, y: START_Y + STEP_Y * 3 }, // Network Interface
3435
{ x: TRANSMISSION_X, y: START_Y + STEP_Y * 4 }, // Transmission
35-
{ x: SERVER_X, y: START_Y + STEP_Y * 3 }, // Network Interface (receiver)
36-
{ x: SERVER_X, y: START_Y + STEP_Y * 2 }, // Internet (receiver)
37-
{ x: SERVER_X, y: START_Y + STEP_Y * 1 }, // Transport (receiver)
38-
{ x: SERVER_X, y: START_Y }, // Application (receiver)
36+
{ x: fromClient ? SERVER_X : CLIENT_X, y: START_Y + STEP_Y * 3 }, // Network Interface (receiver)
37+
{ x: fromClient ? SERVER_X : CLIENT_X, y: START_Y + STEP_Y * 2 }, // Internet (receiver)
38+
{ x: fromClient ? SERVER_X : CLIENT_X, y: START_Y + STEP_Y * 1 }, // Transport (receiver)
39+
{ x: fromClient ? SERVER_X : CLIENT_X, y: START_Y }, // Application (receiver)
3940
]
4041

4142
return positions[props.stage]
42-
}, [props.stage])
43+
}, [props.stage, props.packet.from])
4344

4445
const Icon = props.packet.type.icon
4546

0 commit comments

Comments
 (0)