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;
};
+25
View File
@@ -0,0 +1,25 @@
import type { UserLessonDataType } from '../../types';
import { supabase } from '../../functions/supabase';
export async function fetchUserUpcomingData(
profileId: string | null
): Promise<UserLessonDataType[] | []> {
if (!profileId) {
return [];
}
const { data: userUpcomingData } = await supabase.rpc(
'get_user_upcoming_lessons',
{
profile_id_arg: profileId,
}
);
console.log(`userUpcomingData`, userUpcomingData);
if (!Array.isArray(userUpcomingData)) {
return [];
}
return userUpcomingData;
}
+4
View File
@@ -0,0 +1,4 @@
export type ConfigType = {
isProd: boolean;
supabaseConfig: { url: string; anonKey: string };
};
+16
View File
@@ -0,0 +1,16 @@
export type UserLessonDataType = {
call_url: string;
course_id: string;
course_title: string;
lesson_at: string;
lesson_id: string;
lesson_title: string;
};
type LessonByDayType = {
[dayIndex: number]: UserLessonDataType[];
};
export type LessonsByMonthIndexType = {
[monthIndex: number]: LessonByDayType;
};
+3
View File
@@ -0,0 +1,3 @@
export * from './config';
export * from './dashboard';
export * from './user';
+17
View File
@@ -0,0 +1,17 @@
export interface CurrentSessionType {
access_token: string;
expires_at: number;
expires_in: number;
refresh_token: string;
token_type: string;
}
export interface UserType {
openAuthModal: boolean;
fetchingUser: boolean;
isLoggedIn: boolean;
currentSession: CurrentSessionType | null;
expiresAt: number;
}
export interface ProfileType {}