fix: refine coding project landing actions

This commit is contained in:
inman
2026-09-06 15:45:22 +08:00
parent de8ce283dd
commit faf751be5e
10 changed files with 307 additions and 117 deletions

View File

@@ -1,4 +1,5 @@
const CODING_PROJECT_CREATE_REQUEST_EVENT = 'makelore:coding-project-create-request';
const CODING_PROJECT_OPEN_REQUEST_EVENT = 'makelore:coding-project-open-request';
export function requestCodingProjectCreation(): void {
if (typeof window === 'undefined') return;
@@ -10,3 +11,22 @@ export function subscribeCodingProjectCreationRequest(listener: () => void): ()
window.addEventListener(CODING_PROJECT_CREATE_REQUEST_EVENT, listener);
return () => window.removeEventListener(CODING_PROJECT_CREATE_REQUEST_EVENT, listener);
}
export function requestCodingProjectOpen(projectId: string): void {
if (typeof window === 'undefined') return;
window.dispatchEvent(new CustomEvent(CODING_PROJECT_OPEN_REQUEST_EVENT, {
detail: { projectId },
}));
}
export function subscribeCodingProjectOpenRequest(
listener: (projectId: string) => void,
): () => void {
if (typeof window === 'undefined') return () => undefined;
const handleRequest = (event: Event) => {
const projectId = (event as CustomEvent<{ projectId?: unknown }>).detail?.projectId;
if (typeof projectId === 'string' && projectId.trim()) listener(projectId);
};
window.addEventListener(CODING_PROJECT_OPEN_REQUEST_EVENT, handleRequest);
return () => window.removeEventListener(CODING_PROJECT_OPEN_REQUEST_EVENT, handleRequest);
}