(view: SheetViewMode)
| 437 | }; |
| 438 | |
| 439 | const buildFolderContext = (view: SheetViewMode): FolderContext => { |
| 440 | const rootPath = rootPathFor(view); |
| 441 | |
| 442 | return { |
| 443 | get rootPath() { |
| 444 | return rootPath; |
| 445 | }, |
| 446 | get folders() { |
| 447 | return useSheetContextStore.getState().viewStates[view].folders; |
| 448 | }, |
| 449 | listSubFolders(parent) { |
| 450 | return useSheetContextStore |
| 451 | .getState() |
| 452 | .viewStates[view].folders.filter((path) => |
| 453 | isSubFolder({ parent, path, dig: false }) |
| 454 | ); |
| 455 | }, |
| 456 | ensureFolderPath(path) { |
| 457 | return ensureFolderPath(view, path); |
| 458 | }, |
| 459 | addFolder(path) { |
| 460 | const newPath = ensureFolderPath(view, path); |
| 461 | const current = useSheetContextStore.getState().viewStates[view].folders; |
| 462 | const set = new Set(current); |
| 463 | set.add(newPath); |
| 464 | const next = sortBy([...set]); |
| 465 | useSheetContextStore.getState().setViewFolders(view, next); |
| 466 | persistViewFolders(view, next); |
| 467 | return newPath; |
| 468 | }, |
| 469 | removeFolder(path) { |
| 470 | const current = useSheetContextStore.getState().viewStates[view].folders; |
| 471 | const next = current.filter( |
| 472 | (value) => |
| 473 | !( |
| 474 | value === path || |
| 475 | isSubFolder({ parent: path, path: value, dig: true }) |
| 476 | ) |
| 477 | ); |
| 478 | useSheetContextStore.getState().setViewFolders(view, next); |
| 479 | persistViewFolders(view, next); |
| 480 | }, |
| 481 | moveFolder(from, to) { |
| 482 | const fromPath = ensureFolderPath(view, from); |
| 483 | const toPath = ensureFolderPath(view, to); |
| 484 | const current = useSheetContextStore.getState().viewStates[view].folders; |
| 485 | const next = current.map((path) => { |
| 486 | if (path === fromPath) return toPath; |
| 487 | if (isSubFolder({ parent: fromPath, path, dig: true })) { |
| 488 | return path.replace(fromPath, toPath); |
| 489 | } |
| 490 | return path; |
| 491 | }); |
| 492 | const deduped = sortBy([...new Set(next)]); |
| 493 | useSheetContextStore.getState().setViewFolders(view, deduped); |
| 494 | persistViewFolders(view, deduped); |
| 495 | }, |
| 496 | mergeFolders(paths) { |
no test coverage detected