@@ -6,10 +6,11 @@ import { CacheInfo } from "./CacheInfo.js";
66import { VsCodeButton } from "./VScodeButton.js" ;
77import { JsonRenderer } from "./jsonRenderer.js" ;
88import { ServerRouteInfo , defaultServerRouteState } from "../context/rdtReducer.js" ;
9- import { Tag } from "./Tag.js" ;
9+
1010import { InfoCard } from "./InfoCard.js" ;
1111import { useDevServerConnection } from "../hooks/useDevServerConnection.js" ;
1212import { Icon } from "./icon/Icon.js" ;
13+ import clsx from "clsx" ;
1314
1415const getLoaderData = ( data : string | Record < string , any > ) => {
1516 if ( typeof data === "string" ) {
@@ -54,6 +55,14 @@ const cleanServerInfo = (routeInfo: ServerRouteInfo) => {
5455 } ;
5556} ;
5657
58+ export const ROUTE_COLORS = {
59+ GREEN : "rdt-bg-green-500 rdt-ring-green-500 rdt-text-white" ,
60+ BLUE : "rdt-bg-blue-500 rdt-ring-blue-500 rdt-text-white" ,
61+ TEAL : "rdt-bg-teal-400 rdt-ring-teal-400 rdt-text-white" ,
62+ RED : "rdt-bg-red-500 rdt-ring-red-500 rdt-text-white" ,
63+ PURPLE : "rdt-bg-purple-500 rdt-ring-purple-500 rdt-text-white" ,
64+ } as const ;
65+
5766export const RouteSegmentInfo = ( { route, i } : { route : UIMatch < unknown , unknown > ; i : number } ) => {
5867 const { server, setServerInfo } = useServerInfo ( ) ;
5968 const { isConnected, sendJsonMessage } = useDevServerConnection ( ) ;
@@ -85,39 +94,44 @@ export const RouteSegmentInfo = ({ route, i }: { route: UIMatch<unknown, unknown
8594 onMouseLeave = { ( ) => onHover ( route . id === "root" ? "root" : i . toString ( ) , "leave" ) }
8695 className = "rdt-mb-8 rdt-ml-8"
8796 >
88- < Icon
89- name = "CornerDownRight"
90- className = "rdt-absolute -rdt-left-3 rdt-mt-2 rdt-flex rdt-h-6 rdt-w-6 rdt-items-center rdt-justify-center rdt-rounded-full rdt-bg-blue-900 rdt-ring-4 rdt-ring-blue-900"
91- />
92- < h3 className = "-rdt-mt-3 rdt-mb-1 rdt-flex rdt-items-center rdt-gap-2 rdt-text-lg rdt-font-semibold rdt-text-white" >
93- { route . pathname }
94- < Tag color = { isRoot ? "PURPLE" : isLayout ? "BLUE" : "GREEN" } >
95- { isRoot ? "ROOT" : isLayout ? "LAYOUT" : "ROUTE" }
96- </ Tag >
97- { isConnected && (
98- < VsCodeButton
99- onClick = { ( ) =>
100- sendJsonMessage ( {
101- type : "open-source" ,
102- data : { source : `app/${ route . id } ` } ,
103- } )
104- }
105- />
106- ) }
107- { cacheControl && serverInfo ?. lastLoader . timestamp && (
108- < CacheInfo
109- key = { JSON . stringify ( serverInfo ?. lastLoader ?? "" ) }
110- cacheControl = { cacheControl }
111- cacheDate = { new Date ( serverInfo ?. lastLoader . timestamp ?? "" ) }
112- />
97+ < div
98+ className = { clsx (
99+ "rdt-absolute -rdt-left-4 rdt-flex rdt-h-8 rdt-w-8 rdt-items-center rdt-justify-center rdt-rounded-full" ,
100+ ROUTE_COLORS [ isRoot ? "PURPLE" : isLayout ? "BLUE" : "GREEN" ]
113101 ) }
102+ >
103+ < Icon name = { isRoot ? "Root" : isLayout ? "Layout" : "CornerDownRight" } size = "sm" />
104+ </ div >
105+ < h3 className = "rdt-text-md -rdt-mt-3 rdt-mb-1 rdt-flex rdt-items-center rdt-justify-between rdt-gap-2 rdt-font-semibold rdt-text-white" >
106+ { route . pathname }
107+
108+ < div className = "rdt-flex rdt-gap-2" >
109+ { cacheControl && serverInfo ?. lastLoader . timestamp && (
110+ < CacheInfo
111+ key = { JSON . stringify ( serverInfo ?. lastLoader ?? "" ) }
112+ cacheControl = { cacheControl }
113+ cacheDate = { new Date ( serverInfo ?. lastLoader . timestamp ?? "" ) }
114+ />
115+ ) }
116+ { isConnected && (
117+ < VsCodeButton
118+ onClick = { ( ) =>
119+ sendJsonMessage ( {
120+ type : "open-source" ,
121+ data : { source : `app/${ route . id } ` } ,
122+ } )
123+ }
124+ />
125+ ) }
126+ </ div >
114127 </ h3 >
115128 < div className = "rdt-mb-4" >
116- < time className = "rdt-mb-2 rdt-block rdt-text-sm rdt-font-normal rdt-leading-none rdt-text-gray-500 " >
117- Route location: { route . id }
118- </ time >
119- < div className = "rdt-flex rdt-gap-3" >
120- { loaderData && < InfoCard title = "Route loader data" > { < JsonRenderer data = { loaderData } /> } </ InfoCard > }
129+ < p className = "rdt-mb-2 rdt-block rdt-text-sm rdt-font-normal rdt-leading-none rdt-text-gray-500 " >
130+ Route segment file: { route . id }
131+ </ p >
132+
133+ < div className = "rdt-flex rdt-flex-wrap rdt-gap-6" >
134+ { loaderData && < InfoCard title = "Loader data" > { < JsonRenderer data = { loaderData } /> } </ InfoCard > }
121135 { serverInfo && (
122136 < InfoCard onClear = { clearServerInfoForRoute } title = "Server Info" >
123137 < JsonRenderer data = { cleanServerInfo ( serverInfo ) } />
0 commit comments