Files
classroomio/src/lib/components/Navigation/app.svelte
T

131 lines
3.0 KiB
Svelte
Raw Normal View History

<script>
import { page } from '$app/stores';
2023-08-03 19:31:59 +01:00
import { browser } from '$app/environment';
import NotificationIcon from 'carbon-icons-svelte/lib/Notification.svelte';
import Moon from 'carbon-icons-svelte/lib/Moon.svelte';
import Sun from 'carbon-icons-svelte/lib/Sun.svelte';
2023-08-05 07:47:17 +01:00
import CourseIcon from '$lib/components/Icons/CourseIcon.svelte';
import IconButton from '$lib/components/IconButton/index.svelte';
2023-08-05 07:47:17 +01:00
import { course } from '$lib/components/Course/store';
import { appStore } from '$lib/utils/store/app';
2023-08-05 04:44:32 +01:00
import { currentOrgPath } from '$lib/utils/store/org';
import { toggleBodyByTheme } from '$lib/utils/functions/app';
2023-08-05 07:47:17 +01:00
import { goto } from '$app/navigation';
2023-08-05 04:44:32 +01:00
export let title = '';
export let navClass = '';
2023-08-05 04:44:32 +01:00
export let isCoursePage = false;
function toggleTheme() {
$appStore.isDark = !$appStore.isDark;
toggleBodyByTheme($appStore.isDark);
2023-08-03 19:31:59 +01:00
if (browser) {
localStorage.setItem('theme', $appStore.isDark ? 'dark' : '');
}
}
2023-08-05 04:44:32 +01:00
2023-08-05 08:02:42 +01:00
function getPathName(_isCoursePage = false, slug = '') {
2023-08-05 04:44:32 +01:00
if (!_isCoursePage) {
2023-08-05 07:47:17 +01:00
return '/';
2023-08-05 04:44:32 +01:00
}
2023-08-05 08:02:42 +01:00
return slug ? `/course/${slug}` : `${$currentOrgPath}/courses`;
2023-08-05 04:44:32 +01:00
}
</script>
<nav class="{navClass} flex w-full p-2 md:px-6 bg-blue-700">
<ul class="flex w-full items-center">
2023-08-05 07:47:17 +01:00
<div class="flex items-center text-white">
{#if isCoursePage}
<IconButton
onClick={() => {
goto(`${$currentOrgPath}/courses`);
}}
size="small"
>
2023-08-11 00:19:53 +01:00
<CourseIcon color="#fff" />
2023-08-05 07:47:17 +01:00
</IconButton>
{/if}
2023-08-05 04:44:32 +01:00
<a
2023-08-05 08:02:42 +01:00
href={getPathName(isCoursePage, $course.slug)}
2023-08-05 07:47:17 +01:00
target={isCoursePage && $course.slug ? '_blank' : ''}
2023-08-05 04:44:32 +01:00
title="Go to {isCoursePage ? 'Courses' : 'ClassroomIO Home'}"
id="logo"
2023-08-05 07:47:17 +01:00
class="text-lg {isCoursePage && 'ml-2'}"
2023-08-05 04:44:32 +01:00
>
{isCoursePage ? title : 'ClassroomIO'}
</a>
</div>
<span class="flex-grow" />
<li>
<NotificationIcon size={20} class="text-white mr-2" />
</li>
<li>
<IconButton size="small" onClick={toggleTheme}>
{#if $appStore.isDark}
<Sun size={16} class="text-white" />
{:else}
<Moon size={16} class="text-white" />
{/if}
</IconButton>
</li>
2023-05-02 23:55:26 +00:00
<li />
</ul>
</nav>
<style>
ul {
padding: 0;
}
/* clearfix */
ul::after {
content: '';
display: block;
clear: both;
}
/* li.new-question {
margin-top: 10px;
} */
a {
text-decoration: none;
color: #fff;
font-weight: 700;
}
/* [aria-current] {
color: var(--main-primary-color);
position: relative;
display: inline-block;
}
[aria-current]::after {
position: absolute;
content: '';
width: calc(100% - 3em);
height: 2px;
background-color: var(--main-primary-color);
display: block;
bottom: -17px;
} */
@media only screen and (max-width: 1002px) {
nav.hide {
display: none;
}
ul {
align-items: center;
}
a {
padding: 0 0.5em;
}
}
</style>