(input: {
scope: Accessor<ServerScope>
store: Store<T>
setStore: SetStoreFunction<T>
})
| 66 | } |
| 67 | |
| 68 | export function createServerProjects<T extends ServerProjectState>(input: { |
| 69 | scope: Accessor<ServerScope> |
| 70 | store: Store<T> |
| 71 | setStore: SetStoreFunction<T> |
| 72 | }) { |
| 73 | const setStore = input.setStore as unknown as SetStoreFunction<ServerProjectState> |
| 74 | const current = () => input.store.projects[input.scope()] ?? [] |
| 75 | return { |
| 76 | list: current, |
| 77 | open(directory: string) { |
| 78 | const scope = input.scope() |
| 79 | if (current().some((project) => project.worktree === directory)) return |
| 80 | setStore("projects", scope, [{ worktree: directory, expanded: true }, ...current()]) |
| 81 | }, |
| 82 | close(directory: string) { |
| 83 | setStore( |
| 84 | "projects", |
| 85 | input.scope(), |
| 86 | current().filter((project) => project.worktree !== directory), |
| 87 | ) |
| 88 | }, |
| 89 | expand(directory: string) { |
| 90 | const index = current().findIndex((project) => project.worktree === directory) |
| 91 | if (index !== -1) setStore("projects", input.scope(), index, "expanded", true) |
| 92 | }, |
| 93 | collapse(directory: string) { |
| 94 | const index = current().findIndex((project) => project.worktree === directory) |
| 95 | if (index !== -1) setStore("projects", input.scope(), index, "expanded", false) |
| 96 | }, |
| 97 | move(directory: string, toIndex: number) { |
| 98 | const fromIndex = current().findIndex((project) => project.worktree === directory) |
| 99 | if (fromIndex === -1 || fromIndex === toIndex) return |
| 100 | const next = [...current()] |
| 101 | const [item] = next.splice(fromIndex, 1) |
| 102 | next.splice(toIndex, 0, item) |
| 103 | setStore("projects", input.scope(), next) |
| 104 | }, |
| 105 | last() { |
| 106 | return input.store.lastProject[input.scope()] |
| 107 | }, |
| 108 | touch(directory: string) { |
| 109 | setStore("lastProject", input.scope(), directory) |
| 110 | }, |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | export function resolveServerList(input: { |
| 115 | props?: Array<ServerConnection.Any> |
no outgoing calls
no test coverage detected