1- import { type InitResponse } from "@repo/shared" ;
2- import { getState , setState } from "@repo/webview-shared" ;
3- import {
4- VscodeCollapsible ,
5- VscodeProgressRing ,
6- VscodeScrollable ,
7- } from "@vscode-elements/react-elements" ;
8- import { useEffect , useRef , useState } from "react" ;
9-
10- import { CreateTaskSection } from "./components/CreateTaskSection" ;
111import { ErrorState } from "./components/ErrorState" ;
12- import { NoTemplateState } from "./components/NoTemplateState" ;
132import { NotSupportedState } from "./components/NotSupportedState" ;
14- import { TaskDetailView } from "./components/TaskDetailView" ;
15- import { TaskList } from "./components/TaskList" ;
16- import { useCollapsibleToggle } from "./hooks/useCollapsibleToggle" ;
17- import { useScrollableHeight } from "./hooks/useScrollableHeight" ;
18- import { useSelectedTask } from "./hooks/useSelectedTask" ;
19- import { useTasksApi } from "./hooks/useTasksApi" ;
3+ import { TasksPanel } from "./components/TasksPanel" ;
4+ import { usePersistedState } from "./hooks/usePersistedState" ;
205import { useTasksQuery } from "./hooks/useTasksQuery" ;
216
22- interface PersistedState extends InitResponse {
23- createExpanded : boolean ;
24- historyExpanded : boolean ;
25- }
26-
27- type CollapsibleElement = React . ComponentRef < typeof VscodeCollapsible > ;
28- type ScrollableElement = React . ComponentRef < typeof VscodeScrollable > ;
29-
307export default function App ( ) {
31- const [ restored ] = useState ( ( ) => getState < PersistedState > ( ) ) ;
32- const { tasks, templates, tasksSupported, data, isLoading, error, refetch } =
33- useTasksQuery ( restored ) ;
34-
35- const { selectedTask, isLoadingDetails, selectTask, deselectTask } =
36- useSelectedTask ( tasks ) ;
37-
38- const [ createRef , createOpen , setCreateOpen ] =
39- useCollapsibleToggle < CollapsibleElement > ( restored ?. createExpanded ?? true ) ;
40- const [ historyRef , historyOpen ] = useCollapsibleToggle < CollapsibleElement > (
41- restored ?. historyExpanded ?? true ,
42- ) ;
43-
44- const createScrollRef = useRef < ScrollableElement > ( null ) ;
45- const historyScrollRef = useRef < HTMLDivElement > ( null ) ;
46- useScrollableHeight ( createRef , createScrollRef ) ;
47- useScrollableHeight ( historyRef , historyScrollRef ) ;
48-
49- const { onShowCreateForm } = useTasksApi ( ) ;
50- useEffect ( ( ) => {
51- return onShowCreateForm ( ( ) => setCreateOpen ( true ) ) ;
52- } , [ onShowCreateForm , setCreateOpen ] ) ;
53-
54- useEffect ( ( ) => {
55- if ( data ) {
56- setState < PersistedState > ( {
57- ...data ,
58- createExpanded : createOpen ,
59- historyExpanded : historyOpen ,
60- } ) ;
61- }
62- } , [ data , createOpen , historyOpen ] ) ;
63-
64- function renderHistory ( ) {
65- if ( selectedTask ) {
66- return < TaskDetailView details = { selectedTask } onBack = { deselectTask } /> ;
67- }
68- if ( isLoadingDetails ) {
69- return (
70- < div className = "loading-container" >
71- < VscodeProgressRing />
72- </ div >
73- ) ;
74- }
75- return < TaskList tasks = { tasks } onSelectTask = { selectTask } /> ;
76- }
8+ const persisted = usePersistedState ( ) ;
9+ const { tasksSupported, tasks, templates, refreshing, error, refetch } =
10+ useTasksQuery ( {
11+ initialTasks : persisted . initialTasks ,
12+ initialTemplates : persisted . initialTemplates ,
13+ } ) ;
7714
78- if ( isLoading ) {
79- return (
80- < div className = "loading-container" >
81- < VscodeProgressRing />
82- </ div >
83- ) ;
15+ if ( ! tasksSupported ) {
16+ return < NotSupportedState /> ;
8417 }
8518
8619 if ( error && tasks . length === 0 ) {
@@ -89,35 +22,10 @@ export default function App() {
8922 ) ;
9023 }
9124
92- if ( ! tasksSupported ) {
93- return < NotSupportedState /> ;
94- }
95-
96- if ( templates . length === 0 ) {
97- return < NoTemplateState /> ;
98- }
99-
10025 return (
101- < div className = "tasks-panel" >
102- < VscodeCollapsible
103- ref = { createRef }
104- heading = "Create new task"
105- open = { createOpen }
106- >
107- < VscodeScrollable ref = { createScrollRef } >
108- < CreateTaskSection templates = { templates } />
109- </ VscodeScrollable >
110- </ VscodeCollapsible >
111-
112- < VscodeCollapsible
113- ref = { historyRef }
114- heading = "Task History"
115- open = { historyOpen }
116- >
117- < div ref = { historyScrollRef } className = "collapsible-content" >
118- { renderHistory ( ) }
119- </ div >
120- </ VscodeCollapsible >
121- </ div >
26+ < >
27+ { refreshing && < div className = "refresh-bar" /> }
28+ < TasksPanel tasks = { tasks } templates = { templates } persisted = { persisted } />
29+ </ >
12230 ) ;
12331}
0 commit comments