-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at moving projects to singals
TODO: need to teardown the old picker at the same time as we build the new picker
- Loading branch information
Showing
3 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import vscode, { Disposable, QuickPickItem } from "vscode"; | ||
import { ExtensionBrokerImpl } from "../extension-broker"; | ||
import { computed, effect, signal } from "@preact/signals-react"; | ||
import { firebaseRC } from "./config"; | ||
import { FirebaseProjectMetadata } from "../types/project"; | ||
import { currentUserId } from "./user"; | ||
import { listProjects } from "../cli"; | ||
import { debuglog } from "util"; | ||
import { pluginLogger } from "../logger-wrapper"; | ||
|
||
/** Available projects */ | ||
export const projects = signal<Record<string, FirebaseProjectMetadata[]>>({}); | ||
|
||
/** Currently selected project ID */ | ||
export const currentProjectId = signal(""); | ||
|
||
/** Gets the currently selected project, fallback to first default project in RC file */ | ||
export const currentProject = computed<FirebaseProjectMetadata | undefined>( | ||
() => { | ||
const userProjects = projects.value[currentUserId.value] ?? []; | ||
const wantProjectId = | ||
currentProjectId.value || firebaseRC.value.projects["default"]; | ||
return userProjects.find((p) => p.projectId === wantProjectId); | ||
} | ||
); | ||
|
||
export function registerProject(broker: ExtensionBrokerImpl): Disposable { | ||
effect(() => { | ||
broker.send("notifyProjectChanged", { | ||
projectId: currentProject.value?.projectId ?? "", | ||
}); | ||
}); | ||
|
||
broker.on("getInitialData", () => { | ||
broker.send("notifyProjectChanged", { | ||
projectId: currentProject.value?.projectId ?? "", | ||
}); | ||
}); | ||
|
||
broker.on("selectProject", async () => { | ||
// TODO: implement at the same time we teardown the old picker | ||
// const projects = await listProjects(); | ||
// const id = await promptUserForProject(projects); | ||
// pluginLogger.info("foo:", { id }); | ||
}); | ||
|
||
return { | ||
dispose() {}, | ||
}; | ||
} | ||
|
||
/** Get the user to select a project */ | ||
async function promptUserForProject(projects: FirebaseProjectMetadata[]) { | ||
const items: QuickPickItem[] = projects.map((p) => ({ | ||
label: p.projectId, | ||
description: p.displayName, | ||
})); | ||
|
||
const projectId = await vscode.window.showQuickPick(items); | ||
return projectId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters