Skip to content

Commit ac2ef82

Browse files
committed
chore: refactor of code duplication
1 parent ec5b700 commit ac2ef82

1 file changed

Lines changed: 69 additions & 59 deletions

File tree

src/presentation/pages/Home.vue

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,72 @@
11
<template>
2-
<!-- Unauthorized users -->
3-
<div v-if="user === null">
4-
<Container data-dimensions="large">
5-
<Row :title="t('home.authText')">
6-
<template #right>
7-
<Button
8-
@click="showGoogleAuthPopup"
9-
>
10-
{{ t('auth.login') }}
11-
</Button>
12-
</template>
13-
</Row>
14-
</Container>
15-
</div>
16-
17-
<!-- Authorized users -->
182
<PageBlock
19-
v-else-if="user !== undefined"
203
data-dimensions="large"
214
>
22-
<template #left>
5+
<template
6+
v-if="isUserAuthorized"
7+
#left
8+
>
239
<VerticalMenu
2410
class="menu"
2511
:items="[verticalMenuItems]"
2612
/>
2713
</template>
2814

29-
<router-link
30-
v-if="user"
31-
to="/new"
32-
>
15+
<!-- Unauthorized users -->
16+
<template v-if="!isUserAuthorized">
3317
<Container>
34-
<div :class="$style['container__create-new-note']">
35-
<Row
36-
:title="t('home.createNewNote.title')"
37-
:subtitle="t('home.createNewNote.caption')"
38-
>
39-
<template #left>
40-
<Hammer />
41-
</template>
42-
<template #right>
43-
<Button
44-
secondary
45-
trailing-icon="ChevronRight"
46-
>
47-
{{ t('home.createNewNote.button') }}
48-
</Button>
49-
</template>
50-
</Row>
51-
</div>
18+
<Row :title="t('home.authText')">
19+
<template #right>
20+
<Button
21+
@click="showGoogleAuthPopup"
22+
>
23+
{{ t('auth.login') }}
24+
</Button>
25+
</template>
26+
</Row>
5227
</Container>
53-
</router-link>
54-
55-
<!-- Home content -->
56-
<template v-if="activeMenuItem === 'recents'">
57-
<Heading
58-
:level="1"
59-
:class="$style['page-header']"
60-
>
61-
{{ t('home.sections.recents.title') }}
62-
</Heading>
63-
<NoteList />
6428
</template>
6529

66-
<!-- My notes content -->
67-
<template v-else-if="activeMenuItem === 'myNotes'">
68-
<Heading
69-
:level="1"
70-
:class="$style['page-header']"
30+
<!-- Authorized users -->
31+
<template v-else>
32+
<router-link
33+
to="/new"
7134
>
72-
{{ t('home.sections.myNotes.title') }}
73-
</Heading>
74-
<NoteList :only-created-by-user="true" />
35+
<Container>
36+
<div :class="$style['container__create-new-note']">
37+
<Row
38+
:title="t('home.createNewNote.title')"
39+
:subtitle="t('home.createNewNote.caption')"
40+
>
41+
<template #left>
42+
<Hammer />
43+
</template>
44+
<template #right>
45+
<Button
46+
secondary
47+
trailing-icon="ChevronRight"
48+
>
49+
{{ t('home.createNewNote.button') }}
50+
</Button>
51+
</template>
52+
</Row>
53+
</div>
54+
</Container>
55+
</router-link>
56+
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>
7570
</template>
7671
</PageBlock>
7772
</template>
@@ -93,6 +88,21 @@ const { showGoogleAuthPopup } = useAuth();
9388
// Active menu item state
9489
const activeMenuItem = ref('recents');
9590
91+
const isUserAuthorized = computed(() => user.value !== undefined);
92+
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');
105+
96106
const verticalMenuItems = computed<VerticalMenuItem>(() => {
97107
return {
98108
title: 'Navigation',

0 commit comments

Comments
 (0)