From 8f7f59962a8df39e5a27cf008c6f3b426a2d8435 Mon Sep 17 00:00:00 2001 From: IllGive <93675675+IllGive@users.noreply.github.com> Date: Tue, 5 Sep 2023 16:03:40 -0700 Subject: [PATCH 1/2] setting to choose how many schedules to show --- components/settings/pages/appearance.tsx | 56 ++++++++++++- lib/db/database.types.ts | 85 +++++++++++++++++--- lib/stores/settings.ts | 4 +- pages/index.tsx | 9 ++- supabase/functions/_shared/database.types.ts | 85 +++++++++++++++++--- 5 files changed, 215 insertions(+), 24 deletions(-) diff --git a/components/settings/pages/appearance.tsx b/components/settings/pages/appearance.tsx index e588fb04..0b94fba8 100644 --- a/components/settings/pages/appearance.tsx +++ b/components/settings/pages/appearance.tsx @@ -43,6 +43,44 @@ const Theming: NextPage = () => { }, ]; + const numberOfSchedulesToShow: { + id: Settings["schedulesToShow"]; + name: string; + }[] = [ + { + id: "0", + name: "0", + }, + { + id: "1", + name: "1", + }, + { + id: "2", + name: "2", + }, + { + id: "3", + name: "3", + }, + { + id: "4", + name: "4", + }, + { + id: "5", + name: "5", + }, + { + id: "6", + name: "6", + }, + { + id: "7", + name: "7", + }, + ]; + const homepageViewTypes: { id: Settings["homepageView"]; name: string }[] = [ { id: "auto", @@ -95,7 +133,8 @@ const Theming: NextPage = () => {
Classes
- { sortBySchedule: !settings.sortBySchedule, }) } - /> + /> */} { }); }} /> + theNumber.id == settings.schedulesToShow + )! + } + values={numberOfSchedulesToShow} + onChange={(value) => + set({ schedulesToShow: value.id as Settings["schedulesToShow"] }) + } + />
Assignments
diff --git a/lib/db/database.types.ts b/lib/db/database.types.ts index ecaa5f0b..285b2352 100644 --- a/lib/db/database.types.ts +++ b/lib/db/database.types.ts @@ -149,12 +149,13 @@ export interface Database { id: string; max_grade: number | null; name: string; - publish_date: string | null; + publish_date: string; publish_type: number | null; settings: Json | null; submission_instructions: string | null; term: string | null; type: number; + weight: string | null; }; Insert: { class_id: string; @@ -169,12 +170,13 @@ export interface Database { id?: string; max_grade?: number | null; name: string; - publish_date?: string | null; + publish_date?: string; publish_type?: number | null; settings?: Json | null; submission_instructions?: string | null; term?: string | null; type?: number; + weight?: string | null; }; Update: { class_id?: string; @@ -189,12 +191,13 @@ export interface Database { id?: string; max_grade?: number | null; name?: string; - publish_date?: string | null; + publish_date?: string; publish_type?: number | null; settings?: Json | null; submission_instructions?: string | null; term?: string | null; type?: number; + weight?: string | null; }; Relationships: [ { @@ -366,6 +369,7 @@ export interface Database { content: string; created_at: string; id: string; + resolved: boolean; route: string | null; title: string; topic: string; @@ -377,6 +381,7 @@ export interface Database { content: string; created_at?: string; id?: string; + resolved?: boolean; route?: string | null; title: string; topic: string; @@ -388,6 +393,7 @@ export interface Database { content?: string; created_at?: string; id?: string; + resolved?: boolean; route?: string | null; title?: string; topic?: string; @@ -402,6 +408,49 @@ export interface Database { }, ]; }; + grading_periods: { + Row: { + end_date: string; + id: string; + name: string; + parent: string | null; + school: string; + start_date: string; + weight: number; + }; + Insert: { + end_date: string; + id?: string; + name: string; + parent?: string | null; + school: string; + start_date: string; + weight: number; + }; + Update: { + end_date?: string; + id?: string; + name?: string; + parent?: string | null; + school?: string; + start_date?: string; + weight?: number; + }; + Relationships: [ + { + foreignKeyName: "grading_periods_parent_fkey"; + columns: ["parent"]; + referencedRelation: "grading_periods"; + referencedColumns: ["id"]; + }, + { + foreignKeyName: "grading_periods_school_fkey"; + columns: ["school"]; + referencedRelation: "schools"; + referencedColumns: ["id"]; + }, + ]; + }; relationships: { Row: { parent_id: string[] | null; @@ -450,19 +499,16 @@ export interface Database { created_at: string | null; id: string; name: string; - schedule: Json[] | null; }; Insert: { created_at?: string | null; id?: string; name: string; - schedule?: Json[] | null; }; Update: { created_at?: string | null; id?: string; name?: string; - schedule?: Json[] | null; }; Relationships: []; }; @@ -643,21 +689,40 @@ export interface Database { }; weights: { Row: { + classid: string | null; id: string; name: string; - weight: number | null; + school: string | null; + value: number | null; }; Insert: { + classid?: string | null; id?: string; name: string; - weight?: number | null; + school?: string | null; + value?: number | null; }; Update: { + classid?: string | null; id?: string; name?: string; - weight?: number | null; + school?: string | null; + value?: number | null; }; - Relationships: []; + Relationships: [ + { + foreignKeyName: "weights_classid_fkey"; + columns: ["classid"]; + referencedRelation: "classes"; + referencedColumns: ["id"]; + }, + { + foreignKeyName: "weights_school_fkey"; + columns: ["school"]; + referencedRelation: "schools"; + referencedColumns: ["id"]; + }, + ]; }; }; Views: { diff --git a/lib/stores/settings.ts b/lib/stores/settings.ts index 7776f104..e2c181b9 100644 --- a/lib/stores/settings.ts +++ b/lib/stores/settings.ts @@ -6,10 +6,11 @@ import { Database } from "../db/database.types"; export interface Settings { theme: "light" | "dark" | "system"; compact: boolean; - sortBySchedule: boolean; + sortBySchedule: boolean; //disabled (does not work) homepageAssignments: "all" | "student" | "none"; homepageView: "auto" | "tabbed" | "student" | "teacher"; showAMPM: boolean; + schedulesToShow: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"; } interface SettingsStore { @@ -25,6 +26,7 @@ const defaultSettings: Settings = { homepageAssignments: "student", homepageView: "auto", showAMPM: false, + schedulesToShow: "2", }; export const useSettings = create()( diff --git a/pages/index.tsx b/pages/index.tsx index 94a514e7..fd56547b 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -31,6 +31,9 @@ const Home = () => { day: "numeric", timeZone: "Europe/London", }); + const { + data: { schedulesToShow }, + } = useSettings(); useEffect(() => { const [classes, schedule] = [ @@ -71,7 +74,11 @@ const Home = () => { getAllClasses(supabaseClient, user.id), // read comment in above useEffect as to why I'm fetching 3 dates -Lukas // I'm going to fetch like 5 because weekends or some excuse - Bill - getSchedulesForXDays(supabaseClient, new Date(), 1), + getSchedulesForXDays( + supabaseClient, + new Date(), + parseInt(schedulesToShow) - 1 + ), ]); if (classes.data && classes.data[0]) { diff --git a/supabase/functions/_shared/database.types.ts b/supabase/functions/_shared/database.types.ts index 3f2990ab..df50dbf6 100644 --- a/supabase/functions/_shared/database.types.ts +++ b/supabase/functions/_shared/database.types.ts @@ -149,12 +149,13 @@ export interface Database { id: string max_grade: number | null name: string - publish_date: string | null + publish_date: string publish_type: number | null settings: Json | null submission_instructions: string | null term: string | null type: number + weight: string | null } Insert: { class_id: string @@ -169,12 +170,13 @@ export interface Database { id?: string max_grade?: number | null name: string - publish_date?: string | null + publish_date?: string publish_type?: number | null settings?: Json | null submission_instructions?: string | null term?: string | null type?: number + weight?: string | null } Update: { class_id?: string @@ -189,12 +191,13 @@ export interface Database { id?: string max_grade?: number | null name?: string - publish_date?: string | null + publish_date?: string publish_type?: number | null settings?: Json | null submission_instructions?: string | null term?: string | null type?: number + weight?: string | null } Relationships: [ { @@ -366,6 +369,7 @@ export interface Database { content: string created_at: string id: string + resolved: boolean route: string | null title: string topic: string @@ -377,6 +381,7 @@ export interface Database { content: string created_at?: string id?: string + resolved?: boolean route?: string | null title: string topic: string @@ -388,6 +393,7 @@ export interface Database { content?: string created_at?: string id?: string + resolved?: boolean route?: string | null title?: string topic?: string @@ -402,6 +408,49 @@ export interface Database { } ] } + grading_periods: { + Row: { + end_date: string + id: string + name: string + parent: string | null + school: string + start_date: string + weight: number + } + Insert: { + end_date: string + id?: string + name: string + parent?: string | null + school: string + start_date: string + weight: number + } + Update: { + end_date?: string + id?: string + name?: string + parent?: string | null + school?: string + start_date?: string + weight?: number + } + Relationships: [ + { + foreignKeyName: "grading_periods_parent_fkey" + columns: ["parent"] + referencedRelation: "grading_periods" + referencedColumns: ["id"] + }, + { + foreignKeyName: "grading_periods_school_fkey" + columns: ["school"] + referencedRelation: "schools" + referencedColumns: ["id"] + } + ] + } relationships: { Row: { parent_id: string[] | null @@ -450,19 +499,16 @@ export interface Database { created_at: string | null id: string name: string - schedule: Json[] | null } Insert: { created_at?: string | null id?: string name: string - schedule?: Json[] | null } Update: { created_at?: string | null id?: string name?: string - schedule?: Json[] | null } Relationships: [] } @@ -643,21 +689,40 @@ export interface Database { } weights: { Row: { + classid: string | null id: string name: string - weight: number | null + school: string | null + value: number | null } Insert: { + classid?: string | null id?: string name: string - weight?: number | null + school?: string | null + value?: number | null } Update: { + classid?: string | null id?: string name?: string - weight?: number | null + school?: string | null + value?: number | null } - Relationships: [] + Relationships: [ + { + foreignKeyName: "weights_classid_fkey" + columns: ["classid"] + referencedRelation: "classes" + referencedColumns: ["id"] + }, + { + foreignKeyName: "weights_school_fkey" + columns: ["school"] + referencedRelation: "schools" + referencedColumns: ["id"] + } + ] } } Views: { From 419aa48fb8e32054e0fba4e68d9f2f3e4d187f96 Mon Sep 17 00:00:00 2001 From: IllGive <93675675+IllGive@users.noreply.github.com> Date: Tue, 5 Sep 2023 16:29:40 -0700 Subject: [PATCH 2/2] show more schedules button --- pages/index.tsx | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index fd56547b..e06b7c13 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -5,17 +5,14 @@ import HomepageClassesUI from "../components/class/homepage"; //import { sortClasses } from "../components/class/sorting"; import { AssignmentPreview } from "../components/assignments/assignments"; import ScheduleComponent from "../components/complete/schedule"; -import { - AllClasses, - AllClassesResponse, - getAllClasses, -} from "../lib/db/classes"; +import { AllClasses, getAllClasses } from "../lib/db/classes"; import { Database } from "../lib/db/database.types"; import { ScheduleInterface, getSchedulesForXDays } from "../lib/db/schedule"; import { useSettings } from "../lib/stores/settings"; import blankCanvas from "@/public/svgs/blank-canvas.svg"; import Layout from "@/components/layout/layout"; import Image from "next/image"; +import { Button } from "@/components/misc/button"; const Home = () => { const supabaseClient = useSupabaseClient(); @@ -25,6 +22,7 @@ const Home = () => { const [schedules, setSchedules] = useState< { schedule: ScheduleInterface[]; date: Date }[] >([]); + const [showMoreSchedules, setShowMoreSchedules] = useState(false); const dateFormat = new Intl.DateTimeFormat("en-US", { weekday: "long", month: "long", @@ -145,9 +143,9 @@ const Home = () => { {/* Schedule UI */}
- {schedules.map((schedule, index) => ( + {schedules.slice(0, 2).map((schedule, index) => (

{dateFormat.format(schedule.date)} @@ -160,6 +158,37 @@ const Home = () => { />

))} + {schedules.length > 2 && !showMoreSchedules && ( + + )} + {showMoreSchedules && ( +
+ {schedules.slice(2).map((schedule, index) => ( +
+

+ {dateFormat.format(schedule.date)} +

+ + +
+ ))} + +
+ )}
{Array.isArray(classes) &&