| 1 | import type { ProjectGroupingSettings } from "@t3tools/client-runtime/state/project-grouping"; |
| 2 | import type { SidebarProjectGroupingMode } from "@t3tools/contracts"; |
| 3 | |
| 4 | import type { Preferences } from "../persistence/mobile-preferences"; |
| 5 | |
| 6 | export const DEFAULT_MOBILE_PROJECT_GROUPING_SETTINGS: ProjectGroupingSettings = { |
| 7 | sidebarProjectGroupingMode: "repository", |
| 8 | sidebarProjectGroupingOverrides: {}, |
| 9 | }; |
| 10 | |
| 11 | export function resolveMobileProjectGroupingSettings( |
| 12 | preferences: Preferences, |
| 13 | ): ProjectGroupingSettings { |
| 14 | return { |
| 15 | sidebarProjectGroupingMode: |
| 16 | preferences.projectGroupingMode ?? |
| 17 | (preferences.projectGroupingEnabled === false ? "separate" : "repository"), |
| 18 | sidebarProjectGroupingOverrides: {}, |
| 19 | }; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Dual-writes the legacy boolean for one release so an OTA rollback to an |
| 24 | * older mobile bundle preserves the user's grouping choice. |
| 25 | */ |
| 26 | export function mobileProjectGroupingModePatch( |
| 27 | mode: SidebarProjectGroupingMode, |
| 28 | ): Partial<Preferences> { |
| 29 | return { |
| 30 | projectGroupingMode: mode, |
| 31 | projectGroupingEnabled: mode !== "separate", |
| 32 | }; |
| 33 | } |