@@ -9,21 +9,49 @@ import Comment from './assets/comment.svg';
9
9
import CSV from './assets/csv.svg' ;
10
10
import "./App.scss" ;
11
11
import { useFiles } from "./contexts/FilesContext.tsx" ;
12
+ import { useQuery } from "@tanstack/react-query" ;
13
+ import { TemplateAPI } from "./types/templates.ts" ;
12
14
13
15
function App ( ) {
14
16
const { pathname } = useLocation ( ) ;
15
17
const navigate = useNavigate ( ) ;
16
- const { setFiles } = useFiles ( ) ;
17
- const [ isFirstVisit , setIsFirstVisit ] = useState ( false ) ;
18
+ const { setFiles, templates , setTemplates } = useFiles ( ) ;
19
+ const [ hasMorethan1Template , setHasMoreThanOneTemplate ] = useState ( false ) ;
18
20
21
+ const templateQuery = useQuery ( {
22
+ queryKey : [ "templates" ] ,
23
+ queryFn : TemplateAPI . getTemplates ,
24
+ } ) ;
19
25
useEffect ( ( ) => {
20
- const hasVisited = localStorage . getItem ( "hasVisited" ) ;
21
- if ( ! hasVisited ) {
22
- setIsFirstVisit ( true ) ;
23
- localStorage . setItem ( "hasVisited" , "true" ) ;
26
+ const getTemplates = async ( ) => {
27
+ const templatesJSON = localStorage . getItem ( "templates" ) || "[]" ;
28
+ if ( templateQuery . data && templateQuery . data ?. length > 0 ) {
29
+ setTemplates ( templateQuery . data as [ ] ) ;
30
+ } else if ( templatesJSON ) {
31
+ setTemplates (
32
+ JSON . parse ( templatesJSON ) . map ( ( template ) => ( {
33
+ ...template ,
34
+ updatedAt : template . lastUpdated ,
35
+ } ) ) ,
36
+ ) ;
37
+ } else {
38
+ setTemplates ( [ ] ) ;
39
+ }
40
+ } ;
41
+ getTemplates ( ) ;
42
+ } , [ templateQuery . data ] ) ;
43
+
44
+ useEffect ( ( ) => {
45
+ if ( templates . length > 0 ) {
46
+ setHasMoreThanOneTemplate ( true ) ;
47
+ } else {
48
+ setHasMoreThanOneTemplate ( false ) ;
24
49
}
50
+ } , [ templates . length ] ) ;
51
+
52
+ useEffect ( ( ) => {
25
53
setFiles ( [ ] ) ;
26
- } , [ ] ) ;
54
+ } , [ ] ) ;
27
55
28
56
const navLinks = [
29
57
{ text : "Annotate and Extract" , url : "/" } ,
@@ -58,7 +86,7 @@ function App() {
58
86
< div className = "flex-10 display-flex flex-column bg-idwa-light" data-testid = "content-area" >
59
87
< h2 className = "padding-left-2 bg-white margin-top-0 home-header" data-testid = "home-header" > Annotate and Extract</ h2 >
60
88
< div className = "display-flex flex-justify-center app-content-container width-full" data-testid = "app-content-container" >
61
- { isFirstVisit ? (
89
+ { ! hasMorethan1Template ? (
62
90
< div className = "bg-white display-flex flex-column flex-justify flex-align-center first-time-content" data-testid = "first-time-exp" >
63
91
< h3 className = "first-time-header" data-testid = "first-time-header" >
64
92
Welcome to Report Vision
0 commit comments