Add chips to tab and page nav

This commit is contained in:
rotimi-best
2021-08-31 21:59:17 +03:00
parent 4b75bc862f
commit 72c31a0776
9 changed files with 56 additions and 9 deletions
@@ -61,8 +61,8 @@
/>
{#if mode === MODES.edit || preview}
<PrimaryButton
variant={VARIANTS.OUTLINED}
label={preview ? 'Edit' : 'Preview'}
variant={preview ? VARIANTS.CONTAINED : VARIANTS.OUTLINED}
label={'Toggle Preview'}
onClick={() => (preview = !preview)}
/>
{/if}
@@ -2,13 +2,16 @@ export const tabs = [
{
label: 'Slide',
value: 1,
badgeValue: 0,
},
{
label: 'Note',
value: 2,
badgeValue: 0,
},
{
label: 'Video',
value: 3,
badgeValue: 0,
},
];
@@ -12,12 +12,13 @@
handleUpdateLessonMaterials,
isLessonDirty,
} from '../store/lessons';
import { tabs } from './constants';
import * as CONSTANTS from './constants';
export let mode = MODES.view;
export let prevMode = null;
export let lessonId;
let tabs = CONSTANTS.tabs;
let currentTab = tabs[0].value;
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);
$: addBadgeValueToTab($lesson.materials);
</script>
<Tabs {tabs} {currentTab} {onChange}>
@@ -8,6 +8,7 @@ import {
export const lessons = writable([]);
export const lesson = writable({
id: null,
totalExercises: 0,
materials: {
note: null,
slide_url: null,