CLASSROOMIO-T-8: Add general calendar
This commit is contained in:
@@ -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');
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user