Browse Source

fix collection closing when selecting it

biblius 1 tuần trước cách đây
mục cha
commit
2876a061c0

+ 5 - 5
src/lib/components/SidebarEntry.svelte

@@ -37,7 +37,7 @@
     return true;
   }
 
-  function onRequestClick(e) {
+  function onEntrySelect(e) {
     e.stopPropagation();
 
     if (onCtrlClick(e)) {
@@ -71,7 +71,7 @@
             if (onCtrlClick(e)) {
               return;
             }
-            _state.indexes[id].open = !_state.indexes[id].open;
+            _state.indexes[id].open = false;
           }}
         >
           <ChevronDown />
@@ -85,7 +85,7 @@
             if (onCtrlClick(e)) {
               return;
             }
-            _state.indexes[id].open = !_state.indexes[id].open;
+            _state.indexes[id].open = true;
           }}
         >
           <ChevronRight />
@@ -93,7 +93,7 @@
       {/if}
     {:else if _state.indexes[id]!!.type === "Request"}
       <p
-        onclick={(e) => onRequestClick(e)}
+        onclick={(e) => onEntrySelect(e)}
         class={`cursor-pointer scale-75 text-xs text-center
           ${REQUEST_METHODS.find((m) => m.method === _state.indexes[id].method)?.textColor}`}
       >
@@ -104,7 +104,7 @@
     <p
       class="w-full cursor-pointer py-1 ml-1"
       onclick={(e) => {
-        onRequestClick(e);
+        onEntrySelect(e);
       }}
     >
       {_state.indexes[id].name ||

+ 15 - 7
src/lib/components/WorkspaceEntry.svelte

@@ -123,6 +123,19 @@
     <Select.Root
       type="single"
       value={entry.auth_inherit ? "inherit" : (entry.auth?.toString() ?? "-")}
+      onValueChange={(v) => {
+        if (v === "-") {
+          setEntryAuth(null, false);
+          return;
+        }
+
+        if (v === "inherit") {
+          setEntryAuth(null, true);
+          return;
+        }
+
+        setEntryAuth(parseInt(v), false);
+      }}
     >
       <Select.Trigger>
         {#if entry.auth != null && !entry.auth_inherit}
@@ -135,9 +148,7 @@
       </Select.Trigger>
 
       <Select.Content>
-        <Select.Item onclick={() => setEntryAuth(null, false)} value="-">
-          -
-        </Select.Item>
+        <Select.Item value="-">-</Select.Item>
 
         {#if entry.parent_id != null}
           <Select.Item onclick={() => setEntryAuth(null, true)} value="inherit">
@@ -149,10 +160,7 @@
           <Select.Separator />
 
           {#each _state.auth as auth}
-            <Select.Item
-              onclick={() => setEntryAuth(auth.id, false)}
-              value={auth.id.toString()}
-            >
+            <Select.Item value={auth.id.toString()}>
               {auth.name}
             </Select.Item>
           {/each}

+ 4 - 0
src/lib/state.svelte.ts

@@ -242,6 +242,8 @@ export async function selectEntry(id: number) {
     return;
   }
 
+  const open = state.indexes[id].open;
+
   const entry = await invoke<WorkspaceEntryResponse>("get_workspace_entry", {
     entryId: id,
   });
@@ -249,6 +251,7 @@ export async function selectEntry(id: number) {
   switch (entry.type) {
     case "Collection": {
       state.entry = entry.data;
+      state.entry.open = open;
       break;
     }
     case "Request": {
@@ -260,6 +263,7 @@ export async function selectEntry(id: number) {
         body: entry.data.body,
         path: entry.data.path_params,
         query: entry.data.query_params,
+        open,
       };
       break;
     }