Skip to content

Commit

Permalink
#139 add multiple projects getter to events-store
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreezag committed Jul 28, 2024
1 parent 25a0740 commit 630a912
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/shared/stores/events/events-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useEventsStore = defineStore("eventsStore", {
projects: {
available: [] as TProjects['data'],
activeKey: null as string | null,
default: null as string | null,
defaultKey: null as string | null,
}
}),
getters: {
Expand All @@ -57,7 +57,9 @@ export const useEventsStore = defineStore("eventsStore", {
return Object.entries(cachedIds).filter(([_, value]) => value.length > 0).map(([key]) => key as TEventsGroup)
},
activeProjectKey: ({ projects }) => projects.activeKey,
activeProject: ({ projects }) => projects.available.find((proj) => proj.key === projects.activeKey) || projects.available[0],
availableProjects: ({ projects }) => projects.available,
isMultipleProjects: ({ projects }) => (projects.available.length > 1),
},
actions: {
async initialize (): Promise<void> {
Expand Down Expand Up @@ -220,7 +222,7 @@ export const useEventsStore = defineStore("eventsStore", {
removeStoredProject();
},
setDefaultProject(key: string) {
this.projects.default = key;
this.projects.defaultKey = key;
}
},
});
16 changes: 4 additions & 12 deletions src/widgets/ui/layout-sidebar/layout-sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import {
useEventsStore,
} from "~/src/shared/stores";
import { useConnectionStore } from "~/src/shared/stores/connections";
import type { TProjects } from "~/src/shared/types";
import { BadgeNumber, IconSvg } from "~/src/shared/ui";
import { version } from "../../../../package.json";
import { EVENTS_LINKS_MAP, EVENTS_NAV_ORDER } from "./constants";
const { isConnectedWS } = storeToRefs(useConnectionStore());
const { isVisibleEventCounts, auth } = storeToRefs(useSettingsStore());
const eventsStore = useEventsStore();
const { availableProjects, activeProjectKey } = storeToRefs(eventsStore);
const { availableProjects, isMultipleProjects, activeProject } =
storeToRefs(eventsStore);
const profileStore = useProfileStore();
const { profile } = storeToRefs(profileStore);
Expand Down Expand Up @@ -93,14 +93,6 @@ const toggleProjects = () => {
isVisibleProjects.value = !isVisibleProjects.value;
};
const activeProject = computed(() => {
const project = availableProjects.value.find(
(p) => p.key === activeProjectKey.value,
);
return project as unknown as TProjects["data"][number];
});
const logout = () => {
profileStore.removeToken();
const router = useRouter();
Expand Down Expand Up @@ -146,7 +138,7 @@ const generateRadialGradient = (input: string) =>
<IconSvg class="layout-sidebar__link-icon" name="logo-short" />
</NuxtLink>

<template v-if="availableProjects.length > 0">
<template v-if="isMultipleProjects">
<hr class="layout-sidebar__sep" />

<div class="layout-sidebar__projects">
Expand All @@ -171,7 +163,7 @@ const generateRadialGradient = (input: string) =>
<hr class="layout-sidebar__sep" />
</template>

<template v-if="!availableProjects.length">
<template v-if="!isMultipleProjects">
<NuxtLink to="/" title="Events" class="layout-sidebar__link">
<IconSvg class="layout-sidebar__link-icon" name="events" />
</NuxtLink>
Expand Down

0 comments on commit 630a912

Please sign in to comment.