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

263 lines
7.1 KiB
Svelte
Raw Normal View History

<script lang="ts">
2023-10-15 04:38:37 +00:00
import { onMount } from 'svelte';
import hotkeys from 'hotkeys-js';
2023-10-15 04:38:37 +00:00
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';
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
}
$apps.dropdown = false;
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);
2023-10-15 04:38:37 +00:00
hotkeys('A+1,A+2', function (event, handler) {
2021-05-31 11:28:46 +03:00
event.preventDefault();
switch (handler.key) {
case 'A+1':
handleAppClick(APPS_CONSTANTS.APPS.COMMENTS);
2021-05-31 11:28:46 +03:00
break;
case 'A+2':
2021-05-31 11:28:46 +03:00
handleAppClick(APPS_CONSTANTS.APPS.POLL);
break;
2023-10-15 04:38:37 +00:00
// case 'A+3':
// handleAppClick(APPS_CONSTANTS.APPS.NOTES);
// break;
// case 'A+4':
// handleAppClick(APPS_CONSTANTS.APPS.QANDA);
// break;
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"
toolTipProps={{ title: 'Settings', hotkeys: ['A', '0'] }}
onClick={() => {
2023-10-04 08:18:33 +01:00
handleAppClick();
$apps.dropdown = !$apps.dropdown;
}}
>
<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
toolTipProps={{ title: 'Comments', hotkeys: ['A', '1'] }}
value={APPS_CONSTANTS.APPS.COMMENTS}
onClick={handleAppClick}
buttonClassName="relative"
>
2023-10-15 04:38:37 +00:00
<Chip
value={$lesson.totalComments}
className="absolute -top-1 right-0 bg-primary-600 text-white"
/>
<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
toolTipProps={{ title: 'Poll', hotkeys: ['A', '2'] }}
value={APPS_CONSTANTS.APPS.POLL}
onClick={handleAppClick}
>
<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-15 04:38:37 +00:00
class={`app cursor-auto lg:cursor-ew-resize 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 {
min-width: 280px;
max-width: 300px;
width: 300px;
position: relative;
overflow: auto;
}
}
@media screen and (max-width: 767px) {
.app {
width: 100%;
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>