feat(web): overhaul project settings into a real settings page (#5768)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
5208bdeb0d
commit
288d8e3457
11 files changed
+1609
-756
No files matched your search
@@ -14,6 +14,41 @@ const decodeT3ProjectFile = Schema.decodeExit(T3ProjectFileFromJson);
|
||||
|
||||
const NO_SCRIPTS: ReadonlyArray<T3ProjectFileScript> = [];
|
||||
|
||||
export interface T3ProjectFileState {
|
||||
/**
|
||||
* - `valid`: t3.json exists and decoded.
|
||||
* - `invalid`: t3.json exists but fails to decode (the server then ignores
|
||||
* the whole file, including `iconPath` and every script).
|
||||
* - `missing`: no readable t3.json at the workspace root.
|
||||
* - `loading`: the file query has not settled yet.
|
||||
*/
|
||||
status: "loading" | "missing" | "invalid" | "valid";
|
||||
scripts: ReadonlyArray<T3ProjectFileScript>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decoded state of the project's checked-in `t3.json`, including whether the
|
||||
* file exists but is broken — which the runtime otherwise swallows silently.
|
||||
*/
|
||||
export function useT3ProjectFileState(
|
||||
environmentId: EnvironmentId,
|
||||
cwd: string | null,
|
||||
): T3ProjectFileState {
|
||||
const query = useProjectFileQuery(environmentId, cwd ?? "", T3_PROJECT_FILE_NAME, cwd !== null);
|
||||
const contents = query.data && !query.data.truncated ? query.data.contents : null;
|
||||
const isPending = query.isPending;
|
||||
return useMemo(() => {
|
||||
if (contents === null) {
|
||||
return { status: isPending ? "loading" : "missing", scripts: NO_SCRIPTS } as const;
|
||||
}
|
||||
const decoded = decodeT3ProjectFile(contents);
|
||||
if (Exit.isFailure(decoded)) {
|
||||
return { status: "invalid", scripts: NO_SCRIPTS } as const;
|
||||
}
|
||||
return { status: "valid", scripts: decoded.value.scripts ?? NO_SCRIPTS } as const;
|
||||
}, [contents, isPending]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scripts declared in the project's checked-in `t3.json`, offered in the
|
||||
* scripts menu for import. Missing, truncated, or invalid files resolve to
|
||||
@@ -23,12 +58,5 @@ export function useT3ProjectFileScripts(
|
||||
environmentId: EnvironmentId,
|
||||
cwd: string | null,
|
||||
): ReadonlyArray<T3ProjectFileScript> {
|
||||
const query = useProjectFileQuery(environmentId, cwd ?? "", T3_PROJECT_FILE_NAME, cwd !== null);
|
||||
const contents = query.data && !query.data.truncated ? query.data.contents : null;
|
||||
return useMemo(() => {
|
||||
if (contents === null) return NO_SCRIPTS;
|
||||
const decoded = decodeT3ProjectFile(contents);
|
||||
if (Exit.isFailure(decoded)) return NO_SCRIPTS;
|
||||
return decoded.value.scripts ?? NO_SCRIPTS;
|
||||
}, [contents]);
|
||||
return useT3ProjectFileState(environmentId, cwd).scripts;
|
||||
}
|
||||
Reference in new issue
Block a user