Skip to content

Commit

Permalink
Merge pull request #13 from visagang/main
Browse files Browse the repository at this point in the history
Add local store session for UserProfile
  • Loading branch information
Oceania2018 authored Jan 22, 2024
2 parents b8fb8ab + a8dd6bc commit 5c4f187
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/lib/common/ProfileDropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from '@sveltestrap/sveltestrap';
import { goto } from '$app/navigation';
import { browser } from '$app/environment';
/**
* @type {{ full_name: any; }}
*/
export let user;
function logout() {
if (browser){
localStorage.removeItem('authUser');
Expand All @@ -19,7 +22,7 @@
id="page-header-user-dropdown"
>
<img class="rounded-circle header-profile-user" src='/images/users/user-dummy.jpg' alt="Header Avatar" />
<span class="d-none d-xl-inline-block ms-1" key="t-henry">Henry</span>
<span class="d-none d-xl-inline-block ms-1" key="t-fullname">{user?.full_name}</span>
<i class="mdi mdi-chevron-down d-none d-xl-inline-block" />
</DropdownToggle>
<DropdownMenu end>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { writable } from 'svelte/store';
import { browser } from '$app/environment';

/** @type {Writable<import('$types').UserModel>} */
export const userStore = writable({ id: "" });
export const userStore = writable({ id: "", full_name: "" });

/**
* @returns {Writable<import('$types').UserModel>}
Expand Down
1 change: 1 addition & 0 deletions src/lib/services/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function myInfo() {
const response = await axios.get(endpoints.myInfoUrl);
let user = getUserStore();
user.id = response.data.id;
user.full_name = response.data.full_name;
userStore.set(user);
return response.data;
}
Expand Down
6 changes: 5 additions & 1 deletion src/routes/VerticalLayout/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import ProfileDropdown from '$lib/common/ProfileDropdown.svelte';
import { OverlayScrollbars } from 'overlayscrollbars';
import { PUBLIC_LOGO_URL } from '$env/static/public';
/**
* @type {any}
*/
export let user;
const toggleSideBar = () => {
if (browser) {
Expand Down Expand Up @@ -83,7 +87,7 @@
<LanguageDropdown />
<FullScreenDropdown />
<NotificationDropdown />
<ProfileDropdown />
<ProfileDropdown user={user}/>
</div>
</div>
</header>
8 changes: 7 additions & 1 deletion src/routes/VerticalLayout/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
import Footer from './Footer.svelte';
import { onMount } from 'svelte';
import { getPluginMenu } from '$lib/services/plugin-service';
import { myInfo } from '$lib/services/auth-service';
/** @type {import('$types').PluginMenuDefModel[]} */
let menu;
/**
* @type {import("$types").UserModel}
*/
let user;
const toggleRightBar = () => {
if (browser) {
Expand All @@ -26,14 +31,15 @@
onMount(async () => {
menu = await getPluginMenu();
user = await myInfo();
if (browser) {
document.body.setAttribute('data-layout', 'vertical');
}
});
</script>

<div id="layout-wrapper">
<Header {toggleRightBar} />
<Header user={user} {toggleRightBar} />
{#if menu}
<Sidebar menu={menu}/>
{/if}
Expand Down
5 changes: 4 additions & 1 deletion src/routes/page/dashboard/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
PUBLIC_BRAND_NAME
} from '$env/static/public';
import { onMount } from 'svelte';
import { getUserStore } from '$lib/helpers/store';
let subscribemodal = false;
let user = {full_name: ""};
const togglesubscribemodal = (() => {
subscribemodal = !subscribemodal;
})
onMount(() => {
user = getUserStore();
setTimeout(() => {
subscribemodal = true;
}, 1000);
Expand Down Expand Up @@ -64,7 +67,7 @@
<div class="avatar-md profile-user-wid mb-4">
<Image src='/images/users/user-dummy.jpg' alt="" class="img-thumbnail rounded-circle" />
</div>
<h5 class="font-size-15 text-truncate">Henry Price</h5>
<h5 class="font-size-15 text-truncate">{user?.full_name}</h5>
<p class="text-muted mb-0 text-truncate">Agent Manager</p>
</Col>
<Col sm={8}>
Expand Down

0 comments on commit 5c4f187

Please sign in to comment.