2024-02-11 12:59:00 +11:00
|
|
|
import { onboardingPaths } from 'routes/Onboarding/paths'
|
2024-04-02 10:29:34 -04:00
|
|
|
import { BROWSER_FILE_NAME, BROWSER_PROJECT_NAME, FILE_EXT } from './constants'
|
|
|
|
import { isTauri } from './isTauri'
|
2024-04-25 11:55:11 -07:00
|
|
|
import { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
|
|
|
|
import { ProjectRoute } from 'wasm-lib/kcl/bindings/ProjectRoute'
|
|
|
|
import { parseProjectRoute, readAppSettingsFile } from './tauri'
|
|
|
|
import { parseProjectRoute as parseProjectRouteWasm } from 'lang/wasm'
|
|
|
|
import { readLocalStorageAppSettingsFile } from './settings/settingsUtils'
|
2024-06-24 11:45:40 -04:00
|
|
|
import { err } from 'lib/trap'
|
2024-02-11 12:59:00 +11:00
|
|
|
|
|
|
|
const prependRoutes =
|
|
|
|
(routesObject: Record<string, string>) => (prepend: string) => {
|
|
|
|
return Object.fromEntries(
|
|
|
|
Object.entries(routesObject).map(([constName, path]) => [
|
|
|
|
constName,
|
|
|
|
prepend + path,
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-06-17 15:10:30 -04:00
|
|
|
type OnboardingPaths = {
|
|
|
|
[K in keyof typeof onboardingPaths]: `/onboarding${(typeof onboardingPaths)[K]}`
|
|
|
|
}
|
|
|
|
|
2024-08-09 02:47:25 -04:00
|
|
|
const SETTINGS = '/settings' as const
|
|
|
|
|
|
|
|
export const PATHS = {
|
2024-02-11 12:59:00 +11:00
|
|
|
INDEX: '/',
|
|
|
|
HOME: '/home',
|
|
|
|
FILE: '/file',
|
2024-08-09 02:47:25 -04:00
|
|
|
SETTINGS,
|
|
|
|
SETTINGS_USER: `${SETTINGS}?tab=user` as const,
|
|
|
|
SETTINGS_PROJECT: `${SETTINGS}?tab=project` as const,
|
|
|
|
SETTINGS_KEYBINDINGS: `${SETTINGS}?tab=keybindings` as const,
|
2024-02-11 12:59:00 +11:00
|
|
|
SIGN_IN: '/signin',
|
2024-06-17 15:10:30 -04:00
|
|
|
ONBOARDING: prependRoutes(onboardingPaths)('/onboarding') as OnboardingPaths,
|
2024-04-02 10:29:34 -04:00
|
|
|
} as const
|
|
|
|
export const BROWSER_PATH = `%2F${BROWSER_PROJECT_NAME}%2F${BROWSER_FILE_NAME}${FILE_EXT}`
|
|
|
|
|
2024-04-25 11:55:11 -07:00
|
|
|
export async function getProjectMetaByRouteId(
|
|
|
|
id?: string,
|
2024-06-24 11:45:40 -04:00
|
|
|
configuration?: Configuration | Error
|
2024-04-25 11:55:11 -07:00
|
|
|
): Promise<ProjectRoute | undefined> {
|
2024-04-02 10:29:34 -04:00
|
|
|
if (!id) return undefined
|
|
|
|
|
2024-04-25 11:55:11 -07:00
|
|
|
const inTauri = isTauri()
|
2024-04-02 10:29:34 -04:00
|
|
|
|
2024-06-24 11:45:40 -04:00
|
|
|
if (configuration === undefined) {
|
2024-04-25 11:55:11 -07:00
|
|
|
configuration = inTauri
|
|
|
|
? await readAppSettingsFile()
|
|
|
|
: readLocalStorageAppSettingsFile()
|
2024-04-02 10:29:34 -04:00
|
|
|
}
|
2024-04-25 11:55:11 -07:00
|
|
|
|
2024-06-24 11:45:40 -04:00
|
|
|
if (err(configuration)) return Promise.reject(configuration)
|
|
|
|
|
2024-04-25 11:55:11 -07:00
|
|
|
const route = inTauri
|
|
|
|
? await parseProjectRoute(configuration, id)
|
|
|
|
: parseProjectRouteWasm(configuration, id)
|
|
|
|
|
2024-06-24 11:45:40 -04:00
|
|
|
if (err(route)) return Promise.reject(route)
|
|
|
|
|
2024-04-25 11:55:11 -07:00
|
|
|
return route
|
2024-02-11 12:59:00 +11:00
|
|
|
}
|