Switch to double quotes and reformat codebase with Biome
This commit is contained in:
@@ -1,34 +1,34 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||
import { create } from 'zustand'
|
||||
import { createJSONStorage, persist } from 'zustand/middleware'
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { create } from "zustand";
|
||||
import { createJSONStorage, persist } from "zustand/middleware";
|
||||
|
||||
interface SidebarOrderStoreState {
|
||||
projectOrderByServerId: Record<string, string[]>
|
||||
workspaceOrderByServerAndProject: Record<string, string[]>
|
||||
getProjectOrder: (serverId: string) => string[]
|
||||
setProjectOrder: (serverId: string, keys: string[]) => void
|
||||
getWorkspaceOrder: (serverId: string, projectKey: string) => string[]
|
||||
setWorkspaceOrder: (serverId: string, projectKey: string, keys: string[]) => void
|
||||
projectOrderByServerId: Record<string, string[]>;
|
||||
workspaceOrderByServerAndProject: Record<string, string[]>;
|
||||
getProjectOrder: (serverId: string) => string[];
|
||||
setProjectOrder: (serverId: string, keys: string[]) => void;
|
||||
getWorkspaceOrder: (serverId: string, projectKey: string) => string[];
|
||||
setWorkspaceOrder: (serverId: string, projectKey: string, keys: string[]) => void;
|
||||
}
|
||||
|
||||
function normalizeKeys(keys: string[]): string[] {
|
||||
const seen = new Set<string>()
|
||||
const normalized: string[] = []
|
||||
const seen = new Set<string>();
|
||||
const normalized: string[] = [];
|
||||
|
||||
for (const rawKey of keys) {
|
||||
const key = rawKey.trim()
|
||||
const key = rawKey.trim();
|
||||
if (!key || seen.has(key)) {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
seen.add(key)
|
||||
normalized.push(key)
|
||||
seen.add(key);
|
||||
normalized.push(key);
|
||||
}
|
||||
|
||||
return normalized
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function buildWorkspaceScopeKey(serverId: string, projectKey: string): string {
|
||||
return `${serverId.trim()}::${projectKey.trim()}`
|
||||
return `${serverId.trim()}::${projectKey.trim()}`;
|
||||
}
|
||||
|
||||
export const useSidebarOrderStore = create<SidebarOrderStoreState>()(
|
||||
@@ -37,57 +37,57 @@ export const useSidebarOrderStore = create<SidebarOrderStoreState>()(
|
||||
projectOrderByServerId: {},
|
||||
workspaceOrderByServerAndProject: {},
|
||||
getProjectOrder: (serverId) => {
|
||||
const key = serverId.trim()
|
||||
const key = serverId.trim();
|
||||
if (!key) {
|
||||
return []
|
||||
return [];
|
||||
}
|
||||
return get().projectOrderByServerId[key] ?? []
|
||||
return get().projectOrderByServerId[key] ?? [];
|
||||
},
|
||||
setProjectOrder: (serverId, keys) => {
|
||||
const key = serverId.trim()
|
||||
const key = serverId.trim();
|
||||
if (!key) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
const normalized = normalizeKeys(keys)
|
||||
const normalized = normalizeKeys(keys);
|
||||
set((state) => ({
|
||||
projectOrderByServerId: {
|
||||
...state.projectOrderByServerId,
|
||||
[key]: normalized,
|
||||
},
|
||||
}))
|
||||
}));
|
||||
},
|
||||
getWorkspaceOrder: (serverId, projectKey) => {
|
||||
const serverKey = serverId.trim()
|
||||
const projectScope = projectKey.trim()
|
||||
const serverKey = serverId.trim();
|
||||
const projectScope = projectKey.trim();
|
||||
if (!serverKey || !projectScope) {
|
||||
return []
|
||||
return [];
|
||||
}
|
||||
const scopeKey = buildWorkspaceScopeKey(serverKey, projectScope)
|
||||
return get().workspaceOrderByServerAndProject[scopeKey] ?? []
|
||||
const scopeKey = buildWorkspaceScopeKey(serverKey, projectScope);
|
||||
return get().workspaceOrderByServerAndProject[scopeKey] ?? [];
|
||||
},
|
||||
setWorkspaceOrder: (serverId, projectKey, keys) => {
|
||||
const serverKey = serverId.trim()
|
||||
const projectScope = projectKey.trim()
|
||||
const serverKey = serverId.trim();
|
||||
const projectScope = projectKey.trim();
|
||||
if (!serverKey || !projectScope) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
const scopeKey = buildWorkspaceScopeKey(serverKey, projectScope)
|
||||
const normalized = normalizeKeys(keys)
|
||||
const scopeKey = buildWorkspaceScopeKey(serverKey, projectScope);
|
||||
const normalized = normalizeKeys(keys);
|
||||
set((state) => ({
|
||||
workspaceOrderByServerAndProject: {
|
||||
...state.workspaceOrderByServerAndProject,
|
||||
[scopeKey]: normalized,
|
||||
},
|
||||
}))
|
||||
}));
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'sidebar-project-workspace-order',
|
||||
name: "sidebar-project-workspace-order",
|
||||
storage: createJSONStorage(() => AsyncStorage),
|
||||
partialize: (state) => ({
|
||||
projectOrderByServerId: state.projectOrderByServerId,
|
||||
workspaceOrderByServerAndProject: state.workspaceOrderByServerAndProject,
|
||||
}),
|
||||
}
|
||||
)
|
||||
)
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user