Skip to content

Commit 16d5d24

Browse files
authored
add profile menu (#95)
Fixes #85
1 parent a758cd2 commit 16d5d24

File tree

7 files changed

+53
-41
lines changed

7 files changed

+53
-41
lines changed

locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ userMenu:
4141
language: Language
4242
theme: Theme
4343
options: Options
44+
profile: Profile
4445
logout: Logout
4546
dark: Dark
4647
light: Light

locales/fa.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,6 @@ userMenu:
144144
light: روشن
145145
logout: خروج
146146
options: تنظیمات
147+
profile: پروفایل
147148
signOut: خروج
148149
theme: پوسته

src/components.d.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ declare module 'vue' {
2727
Navbar: typeof import('./components/Navbar.vue')['default']
2828
NBadge: typeof import('naive-ui')['NBadge']
2929
NButton: typeof import('naive-ui')['NButton']
30-
NCard: typeof import('naive-ui')['NCard']
31-
NColorPicker: typeof import('naive-ui')['NColorPicker']
3230
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
3331
NDataTable: typeof import('naive-ui')['NDataTable']
3432
NDialogProvider: typeof import('naive-ui')['NDialogProvider']
35-
NDrawer: typeof import('naive-ui')['NDrawer']
36-
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
37-
NDynamicTags: typeof import('naive-ui')['NDynamicTags']
33+
NDropdown: typeof import('naive-ui')['NDropdown']
3834
NForm: typeof import('naive-ui')['NForm']
3935
NFormItem: typeof import('naive-ui')['NFormItem']
4036
NIcon: typeof import('naive-ui')['NIcon']
@@ -44,16 +40,10 @@ declare module 'vue' {
4440
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
4541
NMenu: typeof import('naive-ui')['NMenu']
4642
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
47-
NModal: typeof import('naive-ui')['NModal']
4843
NNotificationProvider: typeof import('naive-ui')['NNotificationProvider']
4944
NPageHeader: typeof import('naive-ui')['NPageHeader']
5045
NPopselect: typeof import('naive-ui')['NPopselect']
51-
NSelect: typeof import('naive-ui')['NSelect']
52-
NSpace: typeof import('naive-ui')['NSpace']
53-
NSwitch: typeof import('naive-ui')['NSwitch']
5446
NTooltip: typeof import('naive-ui')['NTooltip']
55-
NTreeSelect: typeof import('naive-ui')['NTreeSelect']
56-
NUpload: typeof import('naive-ui')['NUpload']
5747
OrderManagement: typeof import('./components/Orders/OrderManagement.vue')['default']
5848
ProductsManagement: typeof import('./components/Products/ProductsManagement.vue')['default']
5949
ReviewManagement: typeof import('./components/Review/ReviewManagement.vue')['default']

src/components/Navbar.vue

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
<script setup lang="ts">
22
import { storeToRefs } from 'pinia'
3-
import {
4-
PanelLeftContract16Regular as CollapseIcon,
5-
PanelLeftExpand20Regular as OpenIcon,
6-
} from '@vicons/fluent'
73
84
const layoutStore = useLayoutStore()
9-
const { collapsed, forceCollapsed, isRtl } = storeToRefs(layoutStore)
5+
const { isRtl } = storeToRefs(layoutStore)
106
</script>
117

128
<template>
139
<n-page-header class="p-2 navbar">
14-
<template #title>
15-
<n-button mx-2 text size="small" circle @click="layoutStore.toggleSidebar">
16-
<template #icon>
17-
<n-icon size="1.4rem" :class="{ 'rotate-180': isRtl }">
18-
<OpenIcon v-if="collapsed || forceCollapsed" />
19-
<CollapseIcon v-else />
20-
</n-icon>
21-
</template>
22-
</n-button>
23-
</template>
2410
<template #extra>
2511
<div class="flex items-center">
2612
<n-tooltip placement="bottom" trigger="hover">

src/components/Sidebar.vue

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import {
55
PersonSettings20Regular as AccountSettingsIcon,
66
CheckmarkStarburst16Regular as BrandsIcon,
77
Folder32Regular as CategoryIcon,
8+
RadioButton20Filled as CollapseIcon,
89
Color24Regular as ColorsIcon,
910
CommentMultiple32Regular as CommentsIcon,
1011
People28Regular as CustomersIcon,
1112
Home32Regular as DashboardIcon,
1213
Emoji24Regular as FeedbackIcon,
1314
Cart24Regular as InvoicesIcon,
15+
RadioButton20Regular as OpenIcon,
1416
DocumentLink20Regular as PagesIcon,
1517
Apps28Filled as ProductsIcon,
1618
BoxMultiple20Regular as ProductsIcon2,
@@ -26,6 +28,11 @@ import { NIcon } from 'naive-ui/es/icon'
2628
const layoutStore = useLayoutStore()
2729
const { collapsed, forceCollapsed } = storeToRefs(layoutStore)
2830
const { t } = useI18n()
31+
const isHovered = ref(false)
32+
33+
const effectiveCollapsed = computed(() => {
34+
return (collapsed.value || forceCollapsed.value) && !isHovered.value
35+
})
2936
3037
function renderLabel(title: string, path: string) {
3138
return h(
@@ -147,7 +154,7 @@ const menuOptions: MenuOption[] = [
147154
icon: renderIcon(SettingsIcon),
148155
children: [
149156
{
150-
label: () => renderLabel(t('menu.accountSettings'), '/account'),
157+
label: () => renderLabel(t('menu.accountSettings'), '/account/profile'),
151158
key: 'account-settings',
152159
icon: renderIcon(AccountSettingsIcon),
153160
},
@@ -181,15 +188,24 @@ function renderIcon(icon: any, showBadge = false) {
181188

182189
<template>
183190
<n-layout-sider
184-
:native-scrollbar="false" collapse-mode="width" :collapsed-width="64"
185-
:collapsed="collapsed || forceCollapsed" :class="{ collapsed: collapsed || forceCollapsed }"
191+
:native-scrollbar="false" collapse-mode="width" :collapsed-width="64" :collapsed="effectiveCollapsed"
192+
:class="{ collapsed: effectiveCollapsed }" @mouseenter="isHovered = true" @mouseleave="isHovered = false"
186193
>
187194
<div class="logo-container">
188-
<div flex items-center>
195+
<div flex w-full justify-between items-center>
189196
<img src="@/assets/images/logo.png" alt="logo" class="logo">
190197
<h1 class="main-title">
191198
{{ t('title') }}
192199
</h1>
200+
201+
<n-button mx-2 text size="small" circle @click="layoutStore.toggleSidebar">
202+
<template #icon>
203+
<NIcon size="1.2rem" color="#888">
204+
<OpenIcon v-if="collapsed" />
205+
<CollapseIcon v-else />
206+
</NIcon>
207+
</template>
208+
</n-button>
193209
</div>
194210
</div>
195211
<n-menu
@@ -203,7 +219,7 @@ function renderIcon(icon: any, showBadge = false) {
203219
.logo-container {
204220
display: flex;
205221
align-items: center;
206-
padding: 1.5rem 1.1rem 0.5rem 1.1rem;
222+
padding: 1.5rem 0.8rem 0.5rem 1.1rem;
207223
transition: all 100ms;
208224
line-height: 1;
209225

src/components/UserProfile.vue

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
<script setup lang="ts">
22
import type { SelectMixedOption } from 'naive-ui/es/select/src/interface'
3+
import {
4+
DoorArrowRight20Regular as LogoutIcon,
5+
Settings20Regular as SettingsIcon,
6+
} from '@vicons/fluent'
7+
import { NIcon } from 'naive-ui'
8+
import { RouterLink } from 'vue-router'
39
410
const { t } = useI18n()
5-
const selectedItem = ref('')
6-
const router = useRouter()
11+
712
const items: SelectMixedOption[]
813
= [
9-
{ label: t('userMenu.options'), value: '/options' },
1014
{
11-
label: t('userMenu.logout'),
12-
value: '/account/login',
13-
15+
icon: renderIcon(SettingsIcon),
16+
label: renderLabel(t('userMenu.profile'), '/account/profile'),
17+
key: 'options',
18+
},
19+
{
20+
icon: renderIcon(LogoutIcon),
21+
label: renderLabel(t('userMenu.logout'), '/account/login'),
22+
key: 'login',
1423
},
1524
]
1625
17-
function doMenuAction(value: string) {
18-
router.push(value)
26+
function renderIcon(icon: any) {
27+
return () => h(NIcon, null, { default: () => h(icon, {}) })
28+
}
29+
30+
function renderLabel(title: string, path: string) {
31+
return () => h(RouterLink, { to: { path } }, { default: () => title })
1932
}
2033
</script>
2134

2235
<template>
2336
<div class="flex items-center">
24-
<n-popselect v-model="selectedItem" :options="items" @update:value="doMenuAction">
37+
<n-dropdown :options="items">
2538
<img class="avatar" src="@/assets/images/user.png">
26-
</n-popselect>
39+
</n-dropdown>
2740
</div>
2841
</template>
2942

src/pages/Account/profile.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
Profile Page
4+
</div>
5+
</template>

0 commit comments

Comments
 (0)