Add chips to tab and page nav
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
export let className;
|
export let className;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<p class={className ? className : "bg-set"}>{value}</p>
|
<p class={className ? className : 'bg-set mt-2'}>{value}</p>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
p {
|
p {
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
border-radius: 2em;
|
border-radius: 2em;
|
||||||
margin: 6px 0 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.bg-set {
|
.bg-set {
|
||||||
|
|||||||
@@ -61,8 +61,8 @@
|
|||||||
/>
|
/>
|
||||||
{#if mode === MODES.edit || preview}
|
{#if mode === MODES.edit || preview}
|
||||||
<PrimaryButton
|
<PrimaryButton
|
||||||
variant={VARIANTS.OUTLINED}
|
variant={preview ? VARIANTS.CONTAINED : VARIANTS.OUTLINED}
|
||||||
label={preview ? 'Edit' : 'Preview'}
|
label={'Toggle Preview'}
|
||||||
onClick={() => (preview = !preview)}
|
onClick={() => (preview = !preview)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ export const tabs = [
|
|||||||
{
|
{
|
||||||
label: 'Slide',
|
label: 'Slide',
|
||||||
value: 1,
|
value: 1,
|
||||||
|
badgeValue: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Note',
|
label: 'Note',
|
||||||
value: 2,
|
value: 2,
|
||||||
|
badgeValue: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Video',
|
label: 'Video',
|
||||||
value: 3,
|
value: 3,
|
||||||
|
badgeValue: 0,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -12,12 +12,13 @@
|
|||||||
handleUpdateLessonMaterials,
|
handleUpdateLessonMaterials,
|
||||||
isLessonDirty,
|
isLessonDirty,
|
||||||
} from '../store/lessons';
|
} from '../store/lessons';
|
||||||
import { tabs } from './constants';
|
import * as CONSTANTS from './constants';
|
||||||
|
|
||||||
export let mode = MODES.view;
|
export let mode = MODES.view;
|
||||||
export let prevMode = null;
|
export let prevMode = null;
|
||||||
export let lessonId;
|
export let lessonId;
|
||||||
|
|
||||||
|
let tabs = CONSTANTS.tabs;
|
||||||
let currentTab = tabs[0].value;
|
let currentTab = tabs[0].value;
|
||||||
let errors = {};
|
let errors = {};
|
||||||
|
|
||||||
@@ -57,7 +58,31 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addBadgeValueToTab(materials) {
|
||||||
|
const { slide_url, video_url, note } = materials;
|
||||||
|
|
||||||
|
tabs = tabs.map((tab) => {
|
||||||
|
let badgeValue;
|
||||||
|
|
||||||
|
if (tab.value === 1) {
|
||||||
|
badgeValue = !!slide_url ? 1 : 0;
|
||||||
|
} else if (tab.value === 2) {
|
||||||
|
badgeValue = !!note ? 1 : 0;
|
||||||
|
} else {
|
||||||
|
badgeValue =
|
||||||
|
typeof video_url === 'string' ? video_url.split(',').length : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
tab.badgeValue = badgeValue;
|
||||||
|
return tab;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`tabs`, tabs);
|
||||||
|
}
|
||||||
|
|
||||||
$: handleSave(prevMode);
|
$: handleSave(prevMode);
|
||||||
|
|
||||||
|
$: addBadgeValueToTab($lesson.materials);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Tabs {tabs} {currentTab} {onChange}>
|
<Tabs {tabs} {currentTab} {onChange}>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
export const lessons = writable([]);
|
export const lessons = writable([]);
|
||||||
export const lesson = writable({
|
export const lesson = writable({
|
||||||
id: null,
|
id: null,
|
||||||
|
totalExercises: 0,
|
||||||
materials: {
|
materials: {
|
||||||
note: null,
|
note: null,
|
||||||
slide_url: null,
|
slide_url: null,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import NewButton from '../PrimaryContainedButton/index.svelte';
|
import NewButton from '../PrimaryContainedButton/index.svelte';
|
||||||
import TextField from '../Form/TextField.svelte';
|
import TextField from '../Form/TextField.svelte';
|
||||||
|
import Chip from '../Chip/index.svelte';
|
||||||
export let title = '';
|
export let title = '';
|
||||||
export let overidableStyle = '';
|
export let overidableStyle = '';
|
||||||
export let navItems = [];
|
export let navItems = [];
|
||||||
@@ -55,8 +56,15 @@
|
|||||||
{#if Array.isArray(navItems) && navItems.length}
|
{#if Array.isArray(navItems) && navItems.length}
|
||||||
<div class="flex justify-evenly items-center">
|
<div class="flex justify-evenly items-center">
|
||||||
{#each navItems as item}
|
{#each navItems as item}
|
||||||
<a class="mr-5 text-sm {item.isActive && 'active'}" href={item.href}>
|
<a
|
||||||
|
class="mr-5 text-sm flex items-center {item.isActive && 'active'}"
|
||||||
|
href={item.href}
|
||||||
|
>
|
||||||
{item.label}
|
{item.label}
|
||||||
|
|
||||||
|
{#if typeof item.badgeValue === 'number'}
|
||||||
|
<Chip value={item.badgeValue} className="ml-1 bg-gray-300" />
|
||||||
|
{/if}
|
||||||
</a>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
{#if addButtonHref}
|
{#if addButtonHref}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import Chip from '../Chip/index.svelte';
|
||||||
export let tabs = [];
|
export let tabs = [];
|
||||||
export let currentTab;
|
export let currentTab;
|
||||||
export let onChange;
|
export let onChange;
|
||||||
@@ -15,6 +16,9 @@
|
|||||||
on:click={onChange(tab.value)}
|
on:click={onChange(tab.value)}
|
||||||
>
|
>
|
||||||
{tab.label}
|
{tab.label}
|
||||||
|
{#if typeof tab.badgeValue === 'number'}
|
||||||
|
<Chip value={tab.badgeValue} className="ml-1 bg-gray-300" />
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if currentTab === tab.value}
|
{#if currentTab === tab.value}
|
||||||
<span class="absolute w-full top-0 left-0 h-1 bg-blue-500" />
|
<span class="absolute w-full top-0 left-0 h-1 bg-blue-500" />
|
||||||
|
|||||||
@@ -64,15 +64,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
prevLessonId = lessonId;
|
prevLessonId = lessonId;
|
||||||
setLesson(lessonData);
|
|
||||||
|
const totalExercises =
|
||||||
|
lessonData.totalExercises[0] && lessonData.totalExercises[0].count;
|
||||||
|
setLesson(lessonData, totalExercises);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLesson(lessonData) {
|
function setLesson(lessonData, totalExercises) {
|
||||||
if (!lessonData) return;
|
if (!lessonData) return;
|
||||||
|
|
||||||
lesson.update((l) => ({
|
lesson.update((l) => ({
|
||||||
...l,
|
...l,
|
||||||
id: lessonId,
|
id: lessonId,
|
||||||
|
totalExercises,
|
||||||
materials: lessonData,
|
materials: lessonData,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -97,6 +101,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Exercises',
|
label: 'Exercises',
|
||||||
|
badgeValue: $lesson.totalExercises,
|
||||||
isActive: !isMaterialsTabActive,
|
isActive: !isMaterialsTabActive,
|
||||||
href: `${path}/exercises`,
|
href: `${path}/exercises`,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -136,7 +136,9 @@ export function deleteGroupMember(groupMemberId) {
|
|||||||
export function fetchLesson(lessonId) {
|
export function fetchLesson(lessonId) {
|
||||||
return supabase
|
return supabase
|
||||||
.from('lesson')
|
.from('lesson')
|
||||||
.select(`id, note, video_url, slide_url, call_url`)
|
.select(
|
||||||
|
`id, note, video_url, slide_url, call_url, totalExercises:exercise(count)`
|
||||||
|
)
|
||||||
.eq('id', lessonId)
|
.eq('id', lessonId)
|
||||||
.single();
|
.single();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user