chore: refactor menu subscription and event handling in components

This commit is contained in:
Nikita Galaiko 2023-11-24 12:15:42 +01:00 committed by GitButler
parent d477c26930
commit b5712d0b00
2 changed files with 5 additions and 15 deletions

View File

@ -15,8 +15,6 @@
import ShareIssueModal from './ShareIssueModal.svelte';
import { SETTINGS_CONTEXT, loadUserSettings } from '$lib/settings/userSettings';
import { initTheme } from './user/theme';
import { navigating } from '$app/stores';
import { subscribe as menuSubscribe } from '$lib/menu';
export let data: LayoutData;
const { projectService, cloud, user$ } = data;
@ -32,18 +30,6 @@
$: document.documentElement.style.fontSize = zoom + 'rem';
$: userSettings.update((s) => ({ ...s, zoom: zoom }));
// listen for current project events
let unsubscribeMenu = () => {};
$: if ($navigating) {
const fromProject = $navigating?.from?.params?.projectId;
const toProject = $navigating?.to?.params?.projectId;
const projectHasChanged = fromProject !== toProject;
if (projectHasChanged && toProject) {
unsubscribeMenu?.();
unsubscribeMenu = menuSubscribe(toProject);
}
}
onMount(() =>
unsubscribe(
events.on('openNewProjectModal', async () =>

View File

@ -15,6 +15,7 @@
import Button from '$lib/components/Button.svelte';
import { syncToCloud } from '$lib/backend/cloud';
import { handleMenuActions } from '$lib/backend/menu_actions';
import { subscribe as menuSubscribe } from '$lib/menu';
export let data: LayoutData;
@ -40,7 +41,10 @@
handleMenuActions(data.projectId);
onMount(() => {
return unsubscribe(hotkeys.on('Meta+Shift+S', () => syncToCloud($project$?.id)));
return unsubscribe(
menuSubscribe(data.projectId),
hotkeys.on('Meta+Shift+S', () => syncToCloud($project$?.id))
);
});
</script>