1
1
import { useMemo } from 'react'
2
2
import { TCP_IP_LAYERS } from '@/data'
3
- import { Mail } from 'lucide-react'
4
3
import type { PacketStep } from '@/utils/getPacketForStep'
5
4
5
+ const CLIENT_X = 20
6
+ const SERVER_X = 80
7
+ const TRANSMISSION_X = 50
8
+
9
+ const STAGE_TO_X = [
10
+ CLIENT_X ,
11
+ CLIENT_X ,
12
+ CLIENT_X ,
13
+ CLIENT_X ,
14
+ TRANSMISSION_X ,
15
+ SERVER_X ,
16
+ SERVER_X ,
17
+ SERVER_X ,
18
+ SERVER_X ,
19
+ ] as const
20
+
6
21
interface Props {
7
22
packet : PacketStep
8
23
stage : number
9
24
}
10
25
11
26
function EncapsulatedPacket ( props : Props ) {
27
+ const currentPosition = useMemo (
28
+ ( ) => ( {
29
+ x : STAGE_TO_X [ props . stage ] ,
30
+ y : `calc(160px + ((var(--spacing) * 20) * ${ props . stage } ))` ,
31
+ } ) ,
32
+ [ props . stage ] ,
33
+ )
34
+
12
35
const visibleHeaders = useMemo ( ( ) => {
13
36
const visibleHeaders : number [ ] = [ ]
14
37
@@ -19,32 +42,7 @@ function EncapsulatedPacket(props: Props) {
19
42
return visibleHeaders
20
43
} , [ props . stage ] )
21
44
22
- const currentPosition = useMemo ( ( ) => {
23
- const isClientToServer = props . packet . from === 'client'
24
- const clientX = 16
25
- const serverX = 84
26
-
27
- // Calculate positions for each stage
28
- const positions = [
29
- { x : isClientToServer ? clientX : serverX , y : 160 } , // Application
30
- { x : isClientToServer ? clientX : serverX , y : 260 } , // Transport
31
- { x : isClientToServer ? clientX : serverX , y : 360 } , // Internet
32
- { x : isClientToServer ? clientX : serverX , y : 460 } , // Network Interface
33
- {
34
- x : isClientToServer ? ( clientX + serverX ) / 2 : ( serverX + clientX ) / 2 ,
35
- y : 500 ,
36
- } , // Transmission
37
- { x : isClientToServer ? serverX : clientX , y : 460 } , // Network Interface (receiver)
38
- { x : isClientToServer ? serverX : clientX , y : 360 } , // Internet (receiver)
39
- { x : isClientToServer ? serverX : clientX , y : 260 } , // Transport (receiver)
40
- { x : isClientToServer ? serverX : clientX , y : 160 } , // Application (receiver)
41
- ]
42
-
43
- // Get position for current stage
44
- const position = positions [ props . stage ]
45
-
46
- return position
47
- } , [ props . stage , props . packet . from ] )
45
+ const Icon = props . packet . type . icon
48
46
49
47
return (
50
48
< div
@@ -59,8 +57,8 @@ function EncapsulatedPacket(props: Props) {
59
57
{ /* Base packet (envelope) */ }
60
58
< div className = "relative" >
61
59
{ /* Data payload (envelope) */ }
62
- < div className = "w-16 h-12 bg-white border-2 border-black rounded flex items-center justify-center" >
63
- < Mail className = "w-8 h-8 text-black" />
60
+ < div className = "w-16 h-12 mt-2 bg-white border-2 border-black rounded flex items-center justify-center" >
61
+ < Icon className = "w-8 h-8 text-black" />
64
62
</ div >
65
63
66
64
{ /* Layer headers (colored borders) */ }
@@ -89,7 +87,7 @@ function EncapsulatedPacket(props: Props) {
89
87
90
88
{ /* Packet type label */ }
91
89
< div
92
- className = "absolute -bottom-5 left-1/2 transform -translate-x-1/2 text-[10px] font-bold px-1 rounded"
90
+ className = "absolute -bottom-6 left-1/2 transform -translate-x-1/2 whitespace-nowrap text-sm font-bold text-center px-1 rounded"
93
91
style = { { backgroundColor : props . packet . type . color , color : 'white' } }
94
92
>
95
93
{ props . packet . type . name }
0 commit comments