Skip to content

Commit 37071df

Browse files
committed
chore: refactor home page add tabs type
1 parent ac2ef82 commit 37071df

File tree

1 file changed

+48
-63
lines changed

1 file changed

+48
-63
lines changed

src/presentation/pages/Home.vue

Lines changed: 48 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,8 @@
22
<PageBlock
33
data-dimensions="large"
44
>
5-
<template
6-
v-if="isUserAuthorized"
7-
#left
8-
>
9-
<VerticalMenu
10-
class="menu"
11-
:items="[verticalMenuItems]"
12-
/>
13-
</template>
14-
155
<!-- Unauthorized users -->
16-
<template v-if="!isUserAuthorized">
6+
<template v-if="!user">
177
<Container>
188
<Row :title="t('home.authText')">
199
<template #right>
@@ -27,8 +17,19 @@
2717
</Container>
2818
</template>
2919

30-
<!-- Authorized users -->
31-
<template v-else>
20+
<!-- Authorized users - menu -->
21+
<template
22+
v-if="user"
23+
#left
24+
>
25+
<VerticalMenu
26+
class="menu"
27+
:items="[verticalMenuItems]"
28+
/>
29+
</template>
30+
31+
<!-- Authorized users - content -->
32+
<template v-if="user">
3233
<router-link
3334
to="/new"
3435
>
@@ -54,19 +55,16 @@
5455
</Container>
5556
</router-link>
5657

57-
<!-- Home content -->
58-
<template v-if="activeMenuItem === 'recents' || activeMenuItem === 'myNotes'">
59-
<Heading
60-
:level="1"
61-
:class="$style['page-header']"
62-
>
63-
{{ sectionTitle }}
64-
</Heading>
65-
<NoteList
66-
:key="activeMenuItem"
67-
:only-created-by-user="showOnlyUserNotes"
68-
/>
69-
</template>
58+
<Heading
59+
:level="1"
60+
:class="$style['page-header']"
61+
>
62+
{{ sectionTitle }}
63+
</Heading>
64+
<NoteList
65+
:key="activeMenuItem"
66+
:only-created-by-user="tabs[activeMenuItem].onlyCreatedByUser"
67+
/>
7068
</template>
7169
</PageBlock>
7270
</template>
@@ -85,46 +83,33 @@ const { user } = useAppState();
8583
const { t } = useI18n();
8684
const { showGoogleAuthPopup } = useAuth();
8785
88-
// Active menu item state
89-
const activeMenuItem = ref('recents');
86+
const tabs = {
87+
recents: {
88+
titleKey: 'home.sections.recents.title',
89+
onlyCreatedByUser: false,
90+
},
91+
myNotes: {
92+
titleKey: 'home.sections.myNotes.title',
93+
onlyCreatedByUser: true,
94+
},
95+
};
9096
91-
const isUserAuthorized = computed(() => user.value !== undefined);
97+
type TabId = keyof typeof tabs;
9298
93-
const sectionTitle = computed(() => {
94-
if (activeMenuItem.value === 'recents') {
95-
return t('home.sections.recents.title');
96-
}
97-
if (activeMenuItem.value === 'myNotes') {
98-
return t('home.sections.myNotes.title');
99-
}
100-
101-
return '';
102-
});
103-
104-
const showOnlyUserNotes = computed(() => activeMenuItem.value === 'myNotes');
99+
const activeMenuItem = ref<TabId>('recents');
100+
const sectionTitle = computed(() => t(tabs[activeMenuItem.value].titleKey));
105101
106-
const verticalMenuItems = computed<VerticalMenuItem>(() => {
107-
return {
108-
title: 'Navigation',
109-
isActive: false,
110-
items: [
111-
{
112-
title: t('home.sections.recents.title'),
113-
isActive: activeMenuItem.value === 'recents',
114-
onActivate: () => {
115-
activeMenuItem.value = 'recents';
116-
},
117-
},
118-
{
119-
title: t('home.sections.myNotes.title'),
120-
isActive: activeMenuItem.value === 'myNotes',
121-
onActivate: () => {
122-
activeMenuItem.value = 'myNotes';
123-
},
124-
},
125-
],
126-
};
127-
});
102+
const verticalMenuItems = computed<VerticalMenuItem>(() => ({
103+
title: 'Navigation',
104+
isActive: false,
105+
items: (Object.keys(tabs) as TabId[]).map(tabId => ({
106+
title: t(tabs[tabId].titleKey),
107+
isActive: activeMenuItem.value === tabId,
108+
onActivate: () => {
109+
activeMenuItem.value = tabId;
110+
},
111+
})),
112+
}));
128113
129114
/**
130115
* Changing the title in the browser

0 commit comments

Comments
 (0)