Files
classroomio/apps/dashboard/src/lib/components/Org/SideBar.svelte
T

145 lines
4.6 KiB
Svelte
Raw Normal View History

2023-09-11 11:47:30 +01:00
<script lang="ts">
import { page } from '$app/stores';
import HelpIcon from 'carbon-icons-svelte/lib/Help.svelte';
import ForumIcon from 'carbon-icons-svelte/lib/Forum.svelte';
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-11-01 09:45:40 +00:00
import { sideBar } from './store';
2023-05-20 23:53:28 +00:00
const menuItems = [
{
path: '',
label: 'Dashboard'
2023-06-17 19:11:29 +00:00
},
// {
// path: '/quiz',
// label: 'Quizzes'
// },
2023-05-20 23:53:28 +00:00
{
path: '/courses',
label: 'Courses'
2023-05-20 23:53:28 +00:00
},
{
path: '/community',
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',
label: 'Audience'
}
2023-05-20 23:53:28 +00:00
];
2023-09-11 11:47:30 +01:00
function isActive(pagePath: string, itemPath: string) {
const pageLinkItems = pagePath.split('/');
const itemLinkItems = itemPath.split('/');
if (itemLinkItems.length !== pageLinkItems.length) {
return false;
}
return pagePath.includes(itemPath);
}
const toggleSidebar = () => {
2023-11-01 09:45:40 +00:00
$sideBar.hidden = !$sideBar.hidden;
};
</script>
2023-08-11 00:19:53 +01:00
<aside
class={`${
2023-11-01 09:45:40 +00:00
$sideBar.hidden
? '-translate-x-[100%] absolute md:translate-x-0 md:relative z-40'
: 'translate-x-0 absolute md:relative z-40'
} overflow-y-auto transition w-[250px] min-w-[250px] bg-gray-100 dark:bg-neutral-900 h-[calc(100vh-48px)] border border-l-0 border-t-0 border-b-0 border-r-1`}
2023-08-11 00:19:53 +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">
{#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"
/>
{:else if $currentOrg.shortName}
2023-09-16 22:22:24 +01:00
<TextChip
value={$currentOrg.shortName}
className="bg-primary-200 dark:text-black font-bold"
/>
2023-05-02 23:55:26 +00:00
{/if}
<OrgSelector />
<ul class="my-5">
2023-05-20 23:53:28 +00:00
{#each menuItems as menuItem}
<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(
$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-09-11 11:47:30 +01:00
<HomeIcon />
2023-05-20 23:53:28 +00:00
{:else if menuItem.path === '/courses'}
2023-09-11 11:47:30 +01:00
<CourseIcon />
2023-05-20 23:53:28 +00:00
{:else if menuItem.path === '/site'}
<SiteSettingsIcon />
{:else if menuItem.path === '/community'}
2023-09-11 11:47:30 +01:00
<ForumIcon size={24} class="carbon-icon dark:fill-[#fff] fill-[#000]" />
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}
</ul>
</div>
<span class="flex-grow" />
2023-04-22 20:00:37 +00:00
<ul class="my-5 pb-5 px-4">
<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">
<HelpIcon size={20} class="carbon-icon dark:text-white" />
<p class="dark:text-white ml-2">Help</p>
</li>
</a>
<a href="{$currentOrgPath}/settings" class="text-black no-underline" on:click={toggleSidebar}>
<li
2023-08-24 09:40:22 +01:00
class="flex items-center py-3 px-4 mb-2 {NavClasses.item} {isActive(
$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'}"
>
<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>
</li>
</a>
</ul>
</div>
</aside>