Files
classroomio/src/components/Org/SideBar.svelte
T

145 lines
4.1 KiB
Svelte
Raw Normal View History

<script>
import { stores } from '@sapper/app';
import Help from 'carbon-icons-svelte/lib/Help20';
2023-06-17 19:11:29 +00:00
import ForumIcon from 'carbon-icons-svelte/lib/Forum20';
import TextChip from '../../components/Chip/Text.svelte';
import OrgSelector from '../../components/OrgSelector/OrgSelector.svelte';
import HomeIcon from '../../components/Icons/HomeIcon.svelte';
import CourseIcon from '../../components/Icons/CourseIcon.svelte';
2023-06-17 19:11:29 +00:00
import QuizIcon from '../../components/Icons/QuizIcon.svelte';
import SiteSettingsIcon from '../../components/Icons/SiteSettingsIcon.svelte';
import AudienceIcon from '../../components/Icons/AudienceIcon.svelte';
2023-05-02 23:55:26 +00:00
import Avatar from '../../components/Avatar/index.svelte';
2023-05-20 23:53:28 +00:00
import { currentOrg, currentOrgPath } from '../../utils/store/org';
2023-05-02 23:55:26 +00:00
import { profile } from '../../utils/store/user';
let activeClass = 'bg-gray-200 dark:bg-gray-500';
let { page } = stores();
2023-05-20 23:53:28 +00:00
const menuItems = [
{
path: '',
label: 'Home',
},
2023-06-17 19:11:29 +00:00
{
path: '/quiz',
label: 'Quizzes',
},
2023-05-20 23:53:28 +00:00
{
path: '/courses',
label: 'Courses',
},
{
path: '/community',
label: 'Community',
},
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',
},
];
function isActive(pagePath, itemPath) {
const pageLinkItems = pagePath.split('/');
const itemLinkItems = itemPath.split('/');
if (itemLinkItems.length !== pageLinkItems.length) {
return false;
}
return pagePath.includes(itemPath);
}
</script>
<aside class="root bg-gray-100 dark:bg-gray-700 h-full">
<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-05-02 23:55:26 +00:00
{#if $currentOrg.avatar_url}
<Avatar
src={$currentOrg.avatar_url}
name={$currentOrg.name}
shape="rounded-md"
width="w-7"
height="h-7"
/>
{:else}
<TextChip
value={$currentOrg.shortName}
className="bg-blue-200 font-bold"
/>
{/if}
<OrgSelector />
<ul class="my-5">
2023-05-20 23:53:28 +00:00
{#each menuItems as menuItem}
2023-06-17 19:11:29 +00:00
<a
href="{$currentOrgPath}{menuItem.path}"
class="text-black no-underline"
>
2023-05-20 23:53:28 +00:00
<li
class="flex items-center py-3 px-4 mb-2 rounded hover:bg-gray-200 dark:hover:bg-gray-500 {isActive(
$page.path,
`${$currentOrgPath}${menuItem.path}`
) && activeClass}"
>
{#if menuItem.path === ''}
<HomeIcon />
{:else if menuItem.path === '/courses'}
<CourseIcon />
{:else if menuItem.path === '/site'}
<SiteSettingsIcon />
{:else if menuItem.path === '/community'}
2023-06-17 19:11:29 +00:00
<ForumIcon class="carbon-icon" />
{:else if menuItem.path === '/quiz'}
<QuizIcon />
2023-05-20 23:53:28 +00:00
{:else if menuItem.path === '/audience'}
<AudienceIcon />
{/if}
<p class="dark:text-white ml-2">{menuItem.label}</p>
</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">
2023-06-17 19:11:29 +00:00
<a href={$currentOrgPath} class="text-black no-underline">
<li
class="flex items-center py-3 px-4 mb-2 rounded hover:bg-gray-200 dark:hover:bg-gray-500"
>
<Help class="carbon-icon" />
<p class="dark:text-white ml-2">Help</p>
</li>
</a>
2023-06-17 19:11:29 +00:00
<a href="{$currentOrgPath}/settings" class="text-black no-underline">
<li
class="flex items-center py-3 px-4 mb-2 rounded hover:bg-gray-200 dark:hover:bg-gray-500 {isActive(
$page.path,
2023-05-20 23:53:28 +00:00
`${$currentOrgPath}/settings`
) && activeClass}"
>
2023-05-02 23:55:26 +00:00
<Avatar
src={$profile.avatar_url}
name={$profile.username}
width="w-7"
height="h-7"
/>
<p class="dark:text-white ml-2">Settings</p>
</li>
</a>
</ul>
</div>
</aside>
<style>
.root {
width: 250px;
}
</style>