@@ -11,6 +11,7 @@ import { DialogSessionRename } from "./dialog-session-rename"
1111import { useKV } from "../context/kv"
1212import { createDebouncedSignal } from "../util/signal"
1313import { Spinner } from "./spinner"
14+ import { Keybind } from "@/util/keybind"
1415
1516export function DialogSessionList ( ) {
1617 const dialog = useDialog ( )
@@ -22,6 +23,7 @@ export function DialogSessionList() {
2223 const kv = useKV ( )
2324
2425 const [ toDelete , setToDelete ] = createSignal < string > ( )
26+ const [ showArchived , setShowArchived ] = createSignal ( false )
2527 const [ search , setSearch ] = createDebouncedSignal ( "" , 150 )
2628
2729 const [ searchResults ] = createResource ( search , async ( query ) => {
@@ -37,7 +39,11 @@ export function DialogSessionList() {
3739 const options = createMemo ( ( ) => {
3840 const today = new Date ( ) . toDateString ( )
3941 return sessions ( )
40- . filter ( ( x ) => x . parentID === undefined )
42+ . filter ( ( x ) => {
43+ if ( x . parentID !== undefined ) return false
44+ if ( showArchived ( ) ) return ! ! x . time . archived
45+ return ! x . time . archived
46+ } )
4147 . toSorted ( ( a , b ) => b . time . updated - a . time . updated )
4248 . map ( ( x ) => {
4349 const date = new Date ( x . time . updated )
@@ -65,7 +71,7 @@ export function DialogSessionList() {
6571
6672 return (
6773 < DialogSelect
68- title = " Sessions"
74+ title = { showArchived ( ) ? "Archived Sessions" : "Sessions" }
6975 options = { options ( ) }
7076 skipFilter = { true }
7177 current = { currentSessionID ( ) }
@@ -74,32 +80,75 @@ export function DialogSessionList() {
7480 setToDelete ( undefined )
7581 } }
7682 onSelect = { ( option ) => {
83+ if ( showArchived ( ) ) {
84+ sdk . client . session . update ( {
85+ sessionID : option . value ,
86+ time : { archived : 0 } ,
87+ } )
88+ return
89+ }
7790 route . navigate ( {
7891 type : "session" ,
7992 sessionID : option . value ,
8093 } )
8194 dialog . clear ( )
8295 } }
8396 keybind = { [
97+ ...( showArchived ( )
98+ ? [ ]
99+ : [
100+ {
101+ keybind : keybind . all . session_delete ?. [ 0 ] ,
102+ title : "delete" ,
103+ onTrigger : async ( option : { value : string } ) => {
104+ if ( toDelete ( ) === option . value ) {
105+ sdk . client . session . delete ( {
106+ sessionID : option . value ,
107+ } )
108+ setToDelete ( undefined )
109+ return
110+ }
111+ setToDelete ( option . value )
112+ } ,
113+ } ,
114+ {
115+ keybind : keybind . all . session_archive ?. [ 0 ] ,
116+ title : "archive" ,
117+ onTrigger : async ( option : { value : string } ) => {
118+ sdk . client . session . update ( {
119+ sessionID : option . value ,
120+ time : { archived : Date . now ( ) } ,
121+ } )
122+ } ,
123+ } ,
124+ {
125+ keybind : keybind . all . session_rename ?. [ 0 ] ,
126+ title : "rename" ,
127+ onTrigger : async ( option : { value : string } ) => {
128+ dialog . replace ( ( ) => < DialogSessionRename session = { option . value } /> )
129+ } ,
130+ } ,
131+ ] ) ,
132+ ...( showArchived ( )
133+ ? [
134+ {
135+ keybind : keybind . all . session_archive ?. [ 0 ] ,
136+ title : "unarchive" ,
137+ onTrigger : async ( option : { value : string } ) => {
138+ sdk . client . session . update ( {
139+ sessionID : option . value ,
140+ time : { archived : 0 } ,
141+ } )
142+ } ,
143+ } ,
144+ ]
145+ : [ ] ) ,
84146 {
85- keybind : keybind . all . session_delete ?. [ 0 ] ,
86- title : "delete" ,
87- onTrigger : async ( option ) => {
88- if ( toDelete ( ) === option . value ) {
89- sdk . client . session . delete ( {
90- sessionID : option . value ,
91- } )
92- setToDelete ( undefined )
93- return
94- }
95- setToDelete ( option . value )
96- } ,
97- } ,
98- {
99- keybind : keybind . all . session_rename ?. [ 0 ] ,
100- title : "rename" ,
101- onTrigger : async ( option ) => {
102- dialog . replace ( ( ) => < DialogSessionRename session = { option . value } /> )
147+ keybind : Keybind . parse ( "tab" ) [ 0 ] ,
148+ title : showArchived ( ) ? "active" : "archived" ,
149+ onTrigger : async ( ) => {
150+ setShowArchived ( ( prev ) => ! prev )
151+ setToDelete ( undefined )
103152 } ,
104153 } ,
105154 ] }
0 commit comments