mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-26 19:15:25 +03:00
Project Switcher: Prefer derived store
Instead of subscribing to the project list store, create a derived store.
This commit is contained in:
parent
74aed280d2
commit
7bc51460c2
@ -4,6 +4,7 @@
|
||||
import SelectItem from './SelectItem.svelte';
|
||||
import { ProjectService, Project } from '$lib/backend/projects';
|
||||
import { getContext, maybeGetContext } from '$lib/utils/context';
|
||||
import { derived } from 'svelte/store';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
const projectService = getContext(ProjectService);
|
||||
@ -14,17 +15,13 @@
|
||||
title: string;
|
||||
};
|
||||
|
||||
let mappedProjects: ProjectRecord[] = [];
|
||||
|
||||
projectService.projects.subscribe((projectList) => {
|
||||
// Map the projectList to fit the ProjectRecord type
|
||||
mappedProjects = projectList.map((project) => {
|
||||
return {
|
||||
id: project.id,
|
||||
title: project.title
|
||||
};
|
||||
});
|
||||
});
|
||||
// Create a derived store that maps the projects to a simpler structure
|
||||
const mappedProjects = derived(projectService.projects, ($projects) =>
|
||||
$projects.map((project) => ({
|
||||
id: project.id,
|
||||
title: project.title
|
||||
}))
|
||||
);
|
||||
|
||||
let loading = false;
|
||||
let select: Select<ProjectRecord>;
|
||||
@ -37,7 +34,7 @@
|
||||
label="Switch to another project"
|
||||
itemId="id"
|
||||
labelId="title"
|
||||
items={mappedProjects}
|
||||
items={$mappedProjects}
|
||||
placeholder="Select a project..."
|
||||
wide
|
||||
bind:value={selectValue}
|
||||
|
Loading…
Reference in New Issue
Block a user