File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import Elysia, { t } from 'elysia'
22
33const foldersAdd = t . Object ( {
44 name : t . String ( ) ,
5+ parentId : t . Optional ( t . Union ( [ t . Number ( ) , t . Null ( ) ] ) ) ,
56} )
67
78const foldersUpdate = t . Object ( {
Original file line number Diff line number Diff line change 9090 '/' ,
9191 ( { body } ) => {
9292 const db = useDB ( )
93- const { name } = body
93+ const { name, parentId } = body
9494 const now = Date . now ( )
9595
96+ // (parentId)
9697 const { maxOrder } = db
9798 . prepare (
9899 `
99100 SELECT COALESCE(MAX(orderIndex), -1) as maxOrder
100101 FROM folders
101- WHERE parentId IS NULL
102+ WHERE parentId ${ parentId ? '= ?' : ' IS NULL' }
102103 ` ,
103104 )
104- . get ( ) as { maxOrder : number }
105+ . get ( ... ( parentId ? [ parentId ] : [ ] ) ) as { maxOrder : number }
105106
106107 const newOrder = maxOrder + 1
107108
120121 const { lastInsertRowid } = stmt . run (
121122 name ,
122123 'plain_text' ,
123- null ,
124+ parentId ?? null ,
124125 0 ,
125126 now ,
126127 now ,
Original file line number Diff line number Diff line change @@ -240,7 +240,7 @@ provide(treeKeys, {
240240 </ContextMenu .Item >
241241 </template >
242242 <template v-else >
243- <ContextMenu .Item @click =" createFolderAndSelect" >
243+ <ContextMenu .Item @click =" createFolderAndSelect(contextNode?.id) " >
244244 {{ i18n.t("action.new.folder") }}
245245 </ContextMenu .Item >
246246 <ContextMenu .Separator />
Original file line number Diff line number Diff line change @@ -219,7 +219,7 @@ function onResizeTagList(val: number[]) {
219219 </div >
220220 <UiActionButton
221221 :tooltip =" i18n.t('action.new.folder')"
222- @click =" createFolderAndSelect"
222+ @click =" createFolderAndSelect() "
223223 >
224224 <Plus class =" h-4 w-4" />
225225 </UiActionButton >
Original file line number Diff line number Diff line change @@ -281,12 +281,17 @@ async function getFolders(shouldEnsureVisibility = true) {
281281 }
282282}
283283
284- async function createFolder ( ) {
284+ async function createFolder ( parentId ?: number ) {
285285 try {
286286 const { data } = await api . folders . postFolders ( {
287287 name : i18n . t ( 'folder.untitled' ) ,
288+ ...( parentId !== undefined && { parentId } ) ,
288289 } )
289290
291+ if ( parentId ) {
292+ await updateFolder ( parentId , { isOpen : 1 } )
293+ }
294+
290295 await getFolders ( false )
291296
292297 return data . id
@@ -296,9 +301,9 @@ async function createFolder() {
296301 }
297302}
298303
299- async function createFolderAndSelect ( ) {
304+ async function createFolderAndSelect ( parentId ?: number ) {
300305 const { clearSnippetsState } = useSnippets ( )
301- const id = await createFolder ( )
306+ const id = await createFolder ( parentId )
302307
303308 if ( id ) {
304309 await selectFolder ( Number ( id ) )
Original file line number Diff line number Diff line change @@ -160,6 +160,9 @@ export type SnippetsResponse = {
160160
161161export interface FoldersAdd {
162162 name : string ;
163+ parentId ?:
164+ | ( string | ( string | ( string | ( string | ( string | ( string | number ) ) ) ) ) )
165+ | null ;
163166}
164167
165168export type FoldersResponse = {
@@ -465,7 +468,7 @@ export class HttpClient<SecurityDataType = unknown> {
465468
466469/**
467470 * @title massCode API
468- * @version 3.11.0
471+ * @version 4.2.2
469472 *
470473 * Development documentation
471474 */
You can’t perform that action at this time.
0 commit comments