mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 08:33:36 +00:00
refactor: optimize ideation components and store for project-specific job handling
- Updated IdeationDashboard and PromptList components to utilize memoization for improved performance when retrieving generation jobs specific to the current project. - Removed the getJobsForProject function from the ideation store, streamlining job management by directly filtering jobs in the components. - Enhanced the addGenerationJob function to ensure consistent job ID generation format. - Implemented migration logic in the ideation store to clean up legacy jobs without project paths, improving data integrity.
This commit is contained in:
@@ -78,7 +78,6 @@ interface IdeationActions {
|
||||
|
||||
// Generation Jobs
|
||||
addGenerationJob: (projectPath: string, prompt: IdeationPrompt) => string;
|
||||
getJobsForProject: (projectPath: string) => GenerationJob[];
|
||||
updateJobStatus: (
|
||||
jobId: string,
|
||||
status: GenerationJobStatus,
|
||||
@@ -175,7 +174,7 @@ export const useIdeationStore = create<IdeationState & IdeationActions>()(
|
||||
|
||||
// Generation Jobs
|
||||
addGenerationJob: (projectPath, prompt) => {
|
||||
const jobId = `job-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
||||
const jobId = `job-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
||||
const job: GenerationJob = {
|
||||
id: jobId,
|
||||
projectPath,
|
||||
@@ -192,11 +191,6 @@ export const useIdeationStore = create<IdeationState & IdeationActions>()(
|
||||
return jobId;
|
||||
},
|
||||
|
||||
getJobsForProject: (projectPath) => {
|
||||
const state = get();
|
||||
return state.generationJobs.filter((job) => job.projectPath === projectPath);
|
||||
},
|
||||
|
||||
updateJobStatus: (jobId, status, suggestions, error) =>
|
||||
set((state) => ({
|
||||
generationJobs: state.generationJobs.map((job) =>
|
||||
@@ -319,7 +313,7 @@ export const useIdeationStore = create<IdeationState & IdeationActions>()(
|
||||
}),
|
||||
{
|
||||
name: 'automaker-ideation-store',
|
||||
version: 3,
|
||||
version: 4,
|
||||
partialize: (state) => ({
|
||||
// Only persist these fields
|
||||
ideas: state.ideas,
|
||||
@@ -327,6 +321,18 @@ export const useIdeationStore = create<IdeationState & IdeationActions>()(
|
||||
analysisResult: state.analysisResult,
|
||||
filterStatus: state.filterStatus,
|
||||
}),
|
||||
migrate: (persistedState: unknown, version: number) => {
|
||||
const state = persistedState as Record<string, unknown>;
|
||||
if (version < 4) {
|
||||
// Remove legacy jobs that don't have projectPath (from before project-scoping was added)
|
||||
const jobs = (state.generationJobs as GenerationJob[]) || [];
|
||||
return {
|
||||
...state,
|
||||
generationJobs: jobs.filter((job) => job.projectPath !== undefined),
|
||||
};
|
||||
}
|
||||
return state;
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user