CLASSROOMIO-T-8: Add general calendar

This commit is contained in:
Rotimi Best
2021-11-07 00:26:54 +02:00
parent 9d7266f906
commit 9c2350bcee
18 changed files with 579 additions and 190 deletions
+56
View File
@@ -0,0 +1,56 @@
import dayjs from 'dayjs';
import isYesterday from 'dayjs/plugin/isYesterday';
import isToday from 'dayjs/plugin/isToday';
import isTomorrow from 'dayjs/plugin/isTomorrow';
import type { UserLessonDataType, LessonsByMonthIndexType } from '../../types';
dayjs.extend(isYesterday);
dayjs.extend(isToday);
dayjs.extend(isTomorrow);
export const formatUserUpcomingData = (
data: UserLessonDataType[]
): LessonsByMonthIndexType => {
const result: LessonsByMonthIndexType = {};
for (const item of data) {
const { lesson_at } = item;
const lessonAtDate = new Date(lesson_at);
const monthIndex = lessonAtDate.getMonth();
const dateIndex = lessonAtDate.getDate();
if (result[monthIndex]) {
const prevDateData = result[monthIndex][dateIndex];
if (Array.isArray(prevDateData)) {
result[monthIndex] = {
...result[monthIndex],
[dateIndex]: [...prevDateData, item],
};
} else {
result[monthIndex] = { ...result[monthIndex], [dateIndex]: [item] };
}
} else {
result[monthIndex] = { [dateIndex]: [item] };
}
}
return result;
};
export const formatDate = (_selectedDate: string | undefined): string => {
if (!_selectedDate) return '';
const selectedDate = dayjs(_selectedDate);
if (selectedDate.isToday()) {
return 'Today';
} else if (selectedDate.isYesterday()) {
return 'Yesterday';
} else if (selectedDate.isTomorrow()) {
return 'Tomorrow';
}
return selectedDate.format('ddd, MMM D');
};
-24
View File
@@ -1,24 +0,0 @@
import { createClient } from '@supabase/supabase-js';
export let supabase;
export const getSupabase = (config) => {
if (supabase) return supabase;
if (!config && process && process.env) {
config = {
isProd: process.env.NODE_ENV === 'development',
supabaseConfig: {
url: process.env.SVELTE_APP_SUPABASE_URL,
anonKey: process.env.SVELTE_APP_SUPABASE_ANON_KEY,
},
};
}
supabase = createClient(
config.supabaseConfig.url,
config.supabaseConfig.anonKey
);
return supabase;
};
+25
View File
@@ -0,0 +1,25 @@
import { createClient, SupabaseClient } from '@supabase/supabase-js';
import type { ConfigType } from '../types';
export let supabase: SupabaseClient;
export const getSupabase = (config: ConfigType) => {
if (supabase) return supabase;
if (!config && process && process.env) {
config = {
isProd: process.env.NODE_ENV === 'development',
supabaseConfig: {
url: process.env.SVELTE_APP_SUPABASE_URL || '',
anonKey: process.env.SVELTE_APP_SUPABASE_ANON_KEY || '',
},
};
}
supabase = createClient(
config.supabaseConfig.url,
config.supabaseConfig.anonKey
);
return supabase;
};