(sessionKey: string | Accessor<string>)
| 931 | } |
| 932 | }, |
| 933 | tabs(sessionKey: string | Accessor<string>) { |
| 934 | const key = createSessionKeyReader(sessionKey, ensureKey) |
| 935 | const path = createMemo(() => sessionPath(key())) |
| 936 | const tabs = createMemo(() => store.sessionTabs[key()] ?? { all: [] }) |
| 937 | const normalize = (tab: string) => normalizeSessionTab(path(), tab) |
| 938 | const normalizeAll = (all: string[]) => normalizeSessionTabList(path(), all) |
| 939 | return { |
| 940 | tabs, |
| 941 | active: createMemo(() => tabs().active), |
| 942 | all: createMemo(() => tabs().all.filter((tab) => tab !== "review")), |
| 943 | setActive(tab: string | undefined) { |
| 944 | const session = key() |
| 945 | const next = tab ? normalize(tab) : tab |
| 946 | if (!store.sessionTabs[session]) { |
| 947 | setStore("sessionTabs", session, { all: [], active: next }) |
| 948 | } else { |
| 949 | setStore("sessionTabs", session, "active", next) |
| 950 | } |
| 951 | }, |
| 952 | setAll(all: string[]) { |
| 953 | const session = key() |
| 954 | const next = normalizeAll(all).filter((tab) => tab !== "review") |
| 955 | if (!store.sessionTabs[session]) { |
| 956 | setStore("sessionTabs", session, { all: next, active: undefined }) |
| 957 | } else { |
| 958 | setStore("sessionTabs", session, "all", next) |
| 959 | } |
| 960 | }, |
| 961 | async open(tab: string) { |
| 962 | const session = key() |
| 963 | const next = nextSessionTabsForOpen(store.sessionTabs[session], normalize(tab)) |
| 964 | setStore("sessionTabs", session, next) |
| 965 | }, |
| 966 | close(tab: string) { |
| 967 | const session = key() |
| 968 | const current = store.sessionTabs[session] |
| 969 | if (!current) return |
| 970 | |
| 971 | if (tab === "review") { |
| 972 | if (current.active !== tab) return |
| 973 | setStore("sessionTabs", session, "active", current.all[0]) |
| 974 | return |
| 975 | } |
| 976 | |
| 977 | const all = current.all.filter((x) => x !== tab) |
| 978 | if (current.active !== tab) { |
| 979 | setStore("sessionTabs", session, "all", all) |
| 980 | return |
| 981 | } |
| 982 | |
| 983 | const index = current.all.findIndex((f) => f === tab) |
| 984 | const next = current.all[index - 1] ?? current.all[index + 1] ?? all[0] |
| 985 | batch(() => { |
| 986 | setStore("sessionTabs", session, "all", all) |
| 987 | setStore("sessionTabs", session, "active", next) |
| 988 | }) |
| 989 | }, |
| 990 | move(tab: string, to: number) { |
no test coverage detected