1- import { useState , useEffect } from "react" ;
1+ import { useState } from "react" ;
22import { Card } from "./components/Card" ;
33import { Project } from "./data" ;
44import { Tabs , TabsContent , TabsList , TabsTrigger } from "@radix-ui/react-tabs" ;
55import Contributors from "./components/Contributors" ;
66
77function App ( ) {
88 const [ data , setData ] = useState < Project | null > ( null ) ;
9- // const params = new URLSearchParams(windowLocation.search);
10- // const apiParam = params.get("api") || "test"; // Default to 'test' if not specified
119
12- useEffect ( ( ) => {
13- async function fetchData ( ) {
14- const res = await fetch ( "test.json" ) ;
15- const data = await res . json ( ) ;
16- setData ( data ) ;
17- }
18- fetchData ( ) ;
19- } , [ ] ) ;
10+ const handleFileSelect = async (
11+ event : React . ChangeEvent < HTMLInputElement >
12+ ) => {
13+ const file = event . target . files ?. [ 0 ] ;
14+ if ( ! file ) return ;
15+
16+ const reader = new FileReader ( ) ;
17+ reader . onload = ( e ) => {
18+ try {
19+ const json = JSON . parse ( e . target ?. result as string ) ;
20+ setData ( json ) ;
21+ } catch ( error ) {
22+ console . error ( "Error parsing JSON:" , error ) ;
23+ }
24+ } ;
25+ reader . readAsText ( file ) ;
26+ } ;
2027
2128 return (
2229 < >
@@ -26,6 +33,16 @@ function App() {
2633 < h1 className = "text-4xl" > { data . name } </ h1 >
2734 < sub className = "text-xl font-light" > STAPLE Project Dashboard</ sub >
2835 </ header >
36+ < >
37+ < div className = "flex justify-center p-4" >
38+ < input
39+ type = "file"
40+ accept = ".json"
41+ onChange = { handleFileSelect }
42+ className = "block w-full max-w-xs text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100"
43+ />
44+ </ div >
45+ </ >
2946 < Tabs defaultValue = "contributors" >
3047 < TabsList className = "flex w-full max-w-2xl mx-auto my-4 space-x-2 rounded-xl bg-gray-100 p-1" >
3148 < TabsTrigger
@@ -91,7 +108,26 @@ function App() {
91108 < pre > { JSON . stringify ( data , null , 2 ) } </ pre >
92109 </ >
93110 ) : (
94- "Loading..."
111+ < >
112+ < header className = "bg-gray-800 text-white p-4 text-center" >
113+ < sub className = "text-xl font-light" > STAPLE Project Dashboard</ sub >
114+ </ header >
115+ < >
116+ < div className = "flex justify-center p-4" >
117+ < input
118+ type = "file"
119+ accept = ".json"
120+ onChange = { handleFileSelect }
121+ className = "block w-full max-w-xs text-sm text-gray-500
122+ file:mr-4 file:py-2 file:px-4
123+ file:rounded-full file:border-0
124+ file:text-sm file:font-semibold
125+ file:bg-indigo-50 file:text-indigo-700
126+ hover:file:bg-indigo-100"
127+ />
128+ </ div >
129+ </ >
130+ </ >
95131 ) }
96132 </ >
97133 ) ;
0 commit comments