Files
classroomio/apps/dashboard/src/lib/components/Apps/index.svelte
T

245 lines
6.8 KiB
Svelte
Raw Normal View History

<script lang="ts">
2023-10-15 04:38:37 +00:00
import { onMount } from 'svelte';
import { fade } from 'svelte/transition';
import SendAlt from 'carbon-icons-svelte/lib/SendAlt.svelte';
import ChartPie from 'carbon-icons-svelte/lib/ChartPie.svelte';
import IconButton from '$lib/components/IconButton/index.svelte';
import Settings from 'carbon-icons-svelte/lib/Settings.svelte';
import { apps } from './store';
2021-05-29 20:47:46 +03:00
import Chip from '$lib/components/Chip/index.svelte';
import QandA from './components/QandA/index.svelte';
import Comments from './components/Comments/index.svelte';
import Notes from './components/Notes/index.svelte';
import Poll from './components/Poll/index.svelte';
import APPS_CONSTANTS from './constants';
import { browser } from '$app/environment';
2023-11-07 08:51:49 +00:00
import { course } from '$lib/components/Course/store';
import { lesson } from '$lib/components/Course/components/Lesson/store/lessons';
2021-05-29 20:47:46 +03:00
let appBarRef: HTMLDivElement;
let appContentRef: HTMLDivElement;
let topPadding = $apps.isStudent ? '48px' : '109px';
2023-10-04 08:18:33 +01:00
const getResizableSidebar = () => {
if (!browser) return;
return window.innerWidth >= 1024;
};
2021-05-29 20:47:46 +03:00
function handleClose() {
$apps.selectedApp = undefined;
2023-10-15 04:38:37 +00:00
if ($apps.isStudent) {
$apps.open = false;
}
2021-05-29 20:47:46 +03:00
}
function handleAppClick(appName?: string) {
if (appName === $apps.selectedApp) {
2021-05-29 20:47:46 +03:00
handleClose();
} else {
$apps.selectedApp = appName;
2021-05-29 20:47:46 +03:00
}
2023-11-01 09:45:40 +00:00
$apps.dropdown = !$apps.dropdown;
2021-05-29 20:47:46 +03:00
}
function updateTopPadding(isStudent: boolean) {
topPadding = isStudent ? '48px' : '109px';
}
2023-10-15 04:38:37 +00:00
function getAppClass(appName: string, selected: string | undefined) {
return `transition duration-500 delay-150 ease-in-out border-t-0 border-b-0 border-r-0 ${
appName === selected ? 'border-l-4 border-indigo-600 focus:border-indigo-600' : 'border-l-0'
}`;
}
2021-05-31 11:28:46 +03:00
onMount(() => {
updateTopPadding($apps.isStudent);
2021-05-31 11:28:46 +03:00
});
$: updateTopPadding($apps.isStudent);
2023-10-04 08:18:33 +01:00
$: getResizableSidebar();
2021-05-22 22:25:33 +03:00
</script>
<div
style={`--top-padding:${topPadding}`}
class={`${$apps.open ? 'open ' : 'close'} root bg-white dark:bg-black`}
bind:this={appBarRef}
>
2023-10-04 08:18:33 +01:00
<div class="apps">
<div class="lg:hidden mb-2">
<IconButton
buttonClassName="lg:hidden"
2023-11-07 08:51:49 +00:00
toolTipProps={{ title: 'Settings', hotkeys: [] }}
onClick={handleAppClick}
>
<Settings size={24} class="carbon-icon dark:text-white lg:hidden" />
</IconButton>
</div>
2023-10-15 04:38:37 +00:00
<div class="mb-2 relative {getAppClass(APPS_CONSTANTS.APPS.COMMENTS, $apps.selectedApp)}">
<IconButton
2023-11-07 08:51:49 +00:00
toolTipProps={{ title: 'Comments', hotkeys: ['Ctrl/Command', '1'] }}
value={APPS_CONSTANTS.APPS.COMMENTS}
onClick={handleAppClick}
buttonClassName="relative"
>
2023-10-15 04:38:37 +00:00
<Chip
value={$lesson.totalComments}
2023-11-07 08:51:49 +00:00
className="absolute -top-1 right-0 bg-gray-100 text-gray-600 dark:bg-neutral-700 dark:text-white"
2023-10-15 04:38:37 +00:00
/>
<SendAlt size={24} class="carbon-icon dark:text-white" />
</IconButton>
</div>
2023-10-15 04:38:37 +00:00
<div class="mb-2 {getAppClass(APPS_CONSTANTS.APPS.POLL, $apps.selectedApp)}">
<IconButton
2023-11-07 08:51:49 +00:00
toolTipProps={{ title: 'Poll', hotkeys: ['Ctrl/Command', '2'] }}
2023-10-15 04:38:37 +00:00
value={APPS_CONSTANTS.APPS.POLL}
onClick={handleAppClick}
>
2023-11-07 08:51:49 +00:00
<Chip
value={$course.polls.length}
className="absolute -top-1 right-0 bg-gray-100 text-gray-600 dark:bg-neutral-700 dark:text-white"
/>
2023-10-15 04:38:37 +00:00
<ChartPie size={24} class="carbon-icon dark:text-white" />
</IconButton>
</div>
<!-- <div class="mb-2">
<IconButton
2023-10-15 04:38:37 +00:00
toolTipProps={{ title: 'QandA', hotkeys: ['A', '3'] }}
value={APPS_CONSTANTS.APPS.QANDA}
onClick={handleAppClick}
contained={APPS_CONSTANTS.APPS.QANDA === $apps.selectedApp}
>
<Forum size={24} class="carbon-icon dark:text-white" />
</IconButton>
</div>
<div class="mb-2">
<IconButton
toolTipProps={{ title: 'Notes', hotkeys: ['A', '3'] }}
value={APPS_CONSTANTS.APPS.NOTES}
onClick={handleAppClick}
contained={APPS_CONSTANTS.APPS.NOTES === $apps.selectedApp}
>
<AlignBoxTopLeft size={24} class="carbon-icon dark:text-white" />
</IconButton>
</div> -->
2021-05-31 11:28:46 +03:00
</div>
{#if !!$apps.selectedApp}
<div
2023-10-21 07:44:57 +00:00
class="app max-w-[350px] transition ease-in-out delay-150 duration-100"
bind:this={appContentRef}
>
2023-10-15 04:38:37 +00:00
{#key $apps.selectedApp}
<div class="h-full w-full" transition:fade={{ duration: 200 }}>
{#if $apps.selectedApp === APPS_CONSTANTS.APPS.QANDA}
<QandA {handleClose} />
{:else if $apps.selectedApp === APPS_CONSTANTS.APPS.COMMENTS}
<Comments {handleClose} />
{:else if $apps.selectedApp === APPS_CONSTANTS.APPS.POLL}
<Poll {handleClose} />
{:else if $apps.selectedApp === APPS_CONSTANTS.APPS.NOTES}
<Notes {handleClose} />
{/if}
</div>
{/key}
2021-05-31 11:28:46 +03:00
</div>
{/if}
</div>
2021-06-26 21:32:42 +03:00
<style lang="scss">
.root {
height: calc(100vh - 48px);
2021-06-26 21:32:42 +03:00
position: sticky;
top: 0;
border-left: 1px solid var(--border-color);
display: flex;
flex-direction: row;
z-index: 1;
& .apps {
padding-top: 20px;
display: flex;
flex-direction: column;
align-items: center;
width: 60px;
border-right: 1px solid var(--border-color);
height: 100%;
}
& .app {
width: 100%;
position: relative;
overflow: auto;
}
}
@media screen and (min-width: 768px) and (max-width: 1023px) {
.app {
2023-11-01 09:45:40 +00:00
width: 50vw;
position: relative;
overflow: auto;
}
}
@media screen and (max-width: 767px) {
.app {
2023-11-01 09:45:40 +00:00
width: 100vw;
min-width: calc(100vw - 60px);
2021-06-26 21:32:42 +03:00
position: relative;
2021-07-05 10:52:20 +00:00
overflow: auto;
2021-06-26 21:32:42 +03:00
}
}
@media screen and (max-width: 1023px) {
.root {
position: absolute;
height: calc(100vh - var(--top-padding));
top: var(--top-padding);
right: 0;
z-index: 999;
}
.open {
position: absolute;
transform: translateX(0);
transition: all 0.2s ease-in-out;
}
.close {
position: absolute;
transform: translateX(100%);
display: none;
transition: all 0.2s ease-in-out;
}
}
@media screen and (min-width: 1024px) {
.root {
height: calc(100vh - 48px);
position: sticky;
top: 0;
border-left: 1px solid var(--border-color);
display: flex;
flex-direction: row;
z-index: 1;
& .apps {
padding-top: 20px;
display: flex;
flex-direction: column;
align-items: center;
width: 60px;
border-right: 1px solid var(--border-color);
height: 100%;
}
& .app {
width: 100%;
position: relative;
overflow: auto;
}
}
}
2021-06-26 21:32:42 +03:00
</style>