2023-01-03 09:26:08 +01:00
|
|
|
<script>
|
2023-08-02 19:35:27 +01:00
|
|
|
import { page } from '$app/stores';
|
|
|
|
|
import HelpIcon from 'carbon-icons-svelte/lib/Help.svelte';
|
|
|
|
|
import ForumIcon from 'carbon-icons-svelte/lib/Forum.svelte';
|
2023-01-03 09:26:08 +01:00
|
|
|
|
2023-08-02 19:35:27 +01:00
|
|
|
import TextChip from '$lib/components/Chip/Text.svelte';
|
|
|
|
|
import OrgSelector from '$lib/components/OrgSelector/OrgSelector.svelte';
|
|
|
|
|
import HomeIcon from '$lib/components/Icons/HomeIcon.svelte';
|
|
|
|
|
import CourseIcon from '$lib/components/Icons/CourseIcon.svelte';
|
|
|
|
|
import QuizIcon from '$lib/components/Icons/QuizIcon.svelte';
|
|
|
|
|
import SiteSettingsIcon from '$lib/components/Icons/SiteSettingsIcon.svelte';
|
|
|
|
|
import AudienceIcon from '$lib/components/Icons/AudienceIcon.svelte';
|
|
|
|
|
import Avatar from '$lib/components/Avatar/index.svelte';
|
|
|
|
|
import { currentOrg, currentOrgPath } from '$lib/utils/store/org';
|
|
|
|
|
import { profile } from '$lib/utils/store/user';
|
2023-08-11 00:19:53 +01:00
|
|
|
import { NavClasses } from '$lib/utils/constants/reusableClass';
|
2023-09-04 19:48:13 +00:00
|
|
|
import { menu } from './store';
|
2023-01-03 09:26:08 +01:00
|
|
|
|
2023-05-20 23:53:28 +00:00
|
|
|
const menuItems = [
|
|
|
|
|
{
|
|
|
|
|
path: '',
|
2023-08-04 12:41:12 +01:00
|
|
|
label: 'Home'
|
2023-05-20 23:53:28 +00:00
|
|
|
},
|
2023-06-17 19:11:29 +00:00
|
|
|
{
|
|
|
|
|
path: '/quiz',
|
2023-08-04 12:41:12 +01:00
|
|
|
label: 'Quizzes'
|
2023-06-17 19:11:29 +00:00
|
|
|
},
|
2023-05-20 23:53:28 +00:00
|
|
|
{
|
|
|
|
|
path: '/courses',
|
2023-08-04 12:41:12 +01:00
|
|
|
label: 'Courses'
|
2023-05-20 23:53:28 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/community',
|
2023-08-04 12:41:12 +01:00
|
|
|
label: 'Community'
|
2023-05-20 23:53:28 +00:00
|
|
|
},
|
2023-06-17 19:11:29 +00:00
|
|
|
// {
|
|
|
|
|
// path: '/site',
|
|
|
|
|
// label: 'Site settings',
|
|
|
|
|
// },
|
2023-05-20 23:53:28 +00:00
|
|
|
{
|
|
|
|
|
path: '/audience',
|
2023-08-04 12:41:12 +01:00
|
|
|
label: 'Audience'
|
|
|
|
|
}
|
2023-05-20 23:53:28 +00:00
|
|
|
];
|
|
|
|
|
|
2023-01-03 09:26:08 +01:00
|
|
|
function isActive(pagePath, itemPath) {
|
|
|
|
|
const pageLinkItems = pagePath.split('/');
|
|
|
|
|
const itemLinkItems = itemPath.split('/');
|
|
|
|
|
|
|
|
|
|
if (itemLinkItems.length !== pageLinkItems.length) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pagePath.includes(itemPath);
|
|
|
|
|
}
|
2023-09-08 09:17:05 +00:00
|
|
|
const toggleSidebar = () => {
|
|
|
|
|
$menu.hidden = !$menu.hidden;
|
|
|
|
|
};
|
2023-01-03 09:26:08 +01:00
|
|
|
</script>
|
|
|
|
|
|
2023-08-11 00:19:53 +01:00
|
|
|
<aside
|
2023-09-08 09:17:05 +00:00
|
|
|
class={`${
|
2023-09-04 19:48:13 +00:00
|
|
|
$menu.hidden
|
2023-09-08 09:17:05 +00:00
|
|
|
? '-translate-x-[100%] absolute md:translate-x-0 md:relative z-[9999]'
|
|
|
|
|
: 'translate-x-0 absolute md:relative z-[9999]'
|
2023-09-08 15:29:08 +01:00
|
|
|
} transition w-[250px] min-w-[250px] bg-gray-100 dark:bg-gray-800 h-[calc(100vh-48px)] md:h-full border border-l-0 border-t-0 border-b-0 border-r-1`}
|
2023-08-11 00:19:53 +01:00
|
|
|
>
|
2023-01-03 09:26:08 +01:00
|
|
|
<div class="h-full flex flex-col">
|
2023-04-22 20:00:37 +00:00
|
|
|
<div class="border-b border-gray-200 pt-5 px-4">
|
2023-07-28 09:06:03 +01:00
|
|
|
{#if $currentOrg.avatar_url && $currentOrg.name}
|
2023-05-02 23:55:26 +00:00
|
|
|
<Avatar
|
|
|
|
|
src={$currentOrg.avatar_url}
|
|
|
|
|
name={$currentOrg.name}
|
|
|
|
|
shape="rounded-md"
|
|
|
|
|
width="w-7"
|
|
|
|
|
height="h-7"
|
|
|
|
|
/>
|
2023-07-28 09:06:03 +01:00
|
|
|
{:else if $currentOrg.shortName}
|
2023-08-20 19:08:48 +00:00
|
|
|
<TextChip value={$currentOrg.shortName} className="bg-primary-200 font-bold" />
|
2023-05-02 23:55:26 +00:00
|
|
|
{/if}
|
2023-01-03 09:26:08 +01:00
|
|
|
|
|
|
|
|
<OrgSelector />
|
|
|
|
|
|
|
|
|
|
<ul class="my-5">
|
2023-05-20 23:53:28 +00:00
|
|
|
{#each menuItems as menuItem}
|
2023-09-08 09:17:05 +00:00
|
|
|
<a
|
|
|
|
|
href="{$currentOrgPath}{menuItem.path}"
|
|
|
|
|
class="text-black no-underline"
|
|
|
|
|
on:click={toggleSidebar}
|
|
|
|
|
>
|
2023-05-20 23:53:28 +00:00
|
|
|
<li
|
2023-08-24 09:40:22 +01:00
|
|
|
class="flex items-center py-3 px-4 mb-2 {NavClasses.item} {isActive(
|
2023-08-02 19:35:27 +01:00
|
|
|
$page.url.pathname,
|
2023-05-20 23:53:28 +00:00
|
|
|
`${$currentOrgPath}${menuItem.path}`
|
2023-08-20 21:28:55 +01:00
|
|
|
)
|
|
|
|
|
? NavClasses.active
|
|
|
|
|
: 'dark:text-white'}"
|
2023-05-20 23:53:28 +00:00
|
|
|
>
|
|
|
|
|
{#if menuItem.path === ''}
|
2023-08-10 22:53:40 +01:00
|
|
|
<HomeIcon color="#7A797D" />
|
2023-05-20 23:53:28 +00:00
|
|
|
{:else if menuItem.path === '/courses'}
|
2023-08-10 22:53:40 +01:00
|
|
|
<CourseIcon color="#7A797D" />
|
2023-05-20 23:53:28 +00:00
|
|
|
{:else if menuItem.path === '/site'}
|
|
|
|
|
<SiteSettingsIcon />
|
|
|
|
|
{:else if menuItem.path === '/community'}
|
2023-08-20 21:28:55 +01:00
|
|
|
<ForumIcon size={24} class="carbon-icon dark:text-white fill-[#7A797D]" />
|
2023-06-17 19:11:29 +00:00
|
|
|
{:else if menuItem.path === '/quiz'}
|
|
|
|
|
<QuizIcon />
|
2023-05-20 23:53:28 +00:00
|
|
|
{:else if menuItem.path === '/audience'}
|
|
|
|
|
<AudienceIcon />
|
|
|
|
|
{/if}
|
2023-08-20 21:28:55 +01:00
|
|
|
<p class=" ml-2">{menuItem.label}</p>
|
2023-05-20 23:53:28 +00:00
|
|
|
</li>
|
|
|
|
|
</a>
|
|
|
|
|
{/each}
|
2023-01-03 09:26:08 +01:00
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
<span class="flex-grow" />
|
2023-04-22 20:00:37 +00:00
|
|
|
<ul class="my-5 pb-5 px-4">
|
2023-09-08 09:17:05 +00:00
|
|
|
<a href={$currentOrgPath} class="text-black no-underline" on:click={toggleSidebar}>
|
2023-08-20 19:08:48 +00:00
|
|
|
<li class="flex items-center py-3 px-4 mb-2 rounded">
|
2023-08-04 12:41:12 +01:00
|
|
|
<HelpIcon size={20} class="carbon-icon dark:text-white" />
|
2023-05-05 20:19:45 +00:00
|
|
|
<p class="dark:text-white ml-2">Help</p>
|
2023-01-03 09:26:08 +01:00
|
|
|
</li>
|
|
|
|
|
</a>
|
2023-09-08 09:17:05 +00:00
|
|
|
<a href="{$currentOrgPath}/settings" class="text-black no-underline" on:click={toggleSidebar}>
|
2023-01-03 09:26:08 +01:00
|
|
|
<li
|
2023-08-24 09:40:22 +01:00
|
|
|
class="flex items-center py-3 px-4 mb-2 {NavClasses.item} {isActive(
|
2023-08-02 19:35:27 +01:00
|
|
|
$page.url.pathname,
|
2023-05-20 23:53:28 +00:00
|
|
|
`${$currentOrgPath}/settings`
|
2023-08-20 21:28:55 +01:00
|
|
|
)
|
|
|
|
|
? NavClasses.active
|
|
|
|
|
: 'dark:text-white'}"
|
2023-01-03 09:26:08 +01:00
|
|
|
>
|
2023-08-04 12:41:12 +01:00
|
|
|
<Avatar src={$profile.avatar_url} name={$profile.username} width="w-7" height="h-7" />
|
2023-08-20 21:28:55 +01:00
|
|
|
<p class="ml-2">Settings</p>
|
2023-01-03 09:26:08 +01:00
|
|
|
</li>
|
|
|
|
|
</a>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</aside>
|