Skip to content

Commit

Permalink
fix: update workspace provider
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Nov 16, 2024
1 parent 580a93c commit ec202b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apps/yasumu/src/providers/WorkspaceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export function useYasumu() {
return ctx;
}

export function useWorkspace() {
const ctx = useYasumu();

return ctx.workspace;
}

export default function WorkspaceProvider({ children }: React.PropsWithChildren) {
const [yasumu, setYasumu] = useState<Yasumu | null>(null);
const [loading, setLoading] = useState(true);
Expand Down
21 changes: 20 additions & 1 deletion packages/core/src/workspace/YasumuWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,32 @@ export class YasumuWorkspace {
this.#runtime = runtime;
}

/**
* Whether this workspace metadata has been loaded.
*/
public isMetadataLoaded() {
return !!this.#metadata;
}

/**
* The name of this workspace.
*/
public get name() {
return this.#metadata?.name ?? '';
}

/**
* The metadata for this workspace.
*/
public getMetadata(): YasumuWorkspaceMetadata {
public getMetadata(): YasumuWorkspaceMetadata;
public getMetadata(strict?: boolean): YasumuWorkspaceMetadata;
public getMetadata(strict: true): YasumuWorkspaceMetadata;
public getMetadata(strict: false): YasumuWorkspaceMetadata | undefined;
public getMetadata(strict = true): YasumuWorkspaceMetadata | undefined {
const metadata = this.#metadata;

if (!metadata) {
if (!strict) return;
throw new WorkspaceNotLoadedError();
}

Expand Down

0 comments on commit ec202b3

Please sign in to comment.