Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions components/settings/pages/appearance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -95,7 +133,8 @@ const Theming: NextPage = () => {
<Header name="class" page={1}>
Classes
</Header>
<ToggleSection
{/* Disabled */}
{/* <ToggleSection
name="Sort Classes by Schedule"
description="Sort classes based on your schedule. When disabled, classes will be sorted by block number." //rearrangable classes hopefully coming soon TM
enabled={settings.sortBySchedule}
Expand All @@ -104,7 +143,7 @@ const Theming: NextPage = () => {
sortBySchedule: !settings.sortBySchedule,
})
}
/>
/> */}
<DropdownSection
name="Homepage Classes View"
description="Change the way classes are displayed on the homepage. By default, we sample your classes to determine which one fits best for you." //should be clarified
Expand All @@ -118,6 +157,19 @@ const Theming: NextPage = () => {
});
}}
/>
<DropdownSection
name="Number of schedules to show"
description="Choose how many days of schedules to show on your homepage. By default we show two."
currentValue={
numberOfSchedulesToShow.find(
(theNumber) => theNumber.id == settings.schedulesToShow
)!
}
values={numberOfSchedulesToShow}
onChange={(value) =>
set({ schedulesToShow: value.id as Settings["schedulesToShow"] })
}
/>
Comment on lines +160 to +172
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason the dropdown section isn't always to the right

<Header name="assignment" page={1}>
Assignments
</Header>
Expand Down
85 changes: 75 additions & 10 deletions lib/db/database.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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: [
{
Expand Down Expand Up @@ -366,6 +369,7 @@ export interface Database {
content: string;
created_at: string;
id: string;
resolved: boolean;
route: string | null;
title: string;
topic: string;
Expand All @@ -377,6 +381,7 @@ export interface Database {
content: string;
created_at?: string;
id?: string;
resolved?: boolean;
route?: string | null;
title: string;
topic: string;
Expand All @@ -388,6 +393,7 @@ export interface Database {
content?: string;
created_at?: string;
id?: string;
resolved?: boolean;
route?: string | null;
title?: string;
topic?: string;
Expand All @@ -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;
Expand Down Expand Up @@ -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: [];
};
Expand Down Expand Up @@ -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: {
Expand Down
4 changes: 3 additions & 1 deletion lib/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Copy link
Contributor

@quick007 quick007 Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for future reference, it might be easier to use an enum or normal numbers, but this works just as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried that, turns out that settings wanted strings and I was too tired to deal with it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, my bad then

}

interface SettingsStore {
Expand All @@ -25,6 +26,7 @@ const defaultSettings: Settings = {
homepageAssignments: "student",
homepageView: "auto",
showAMPM: false,
schedulesToShow: "2",
};

export const useSettings = create<SettingsStore>()(
Expand Down
52 changes: 44 additions & 8 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database>();
Expand All @@ -25,12 +22,16 @@ 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",
day: "numeric",
timeZone: "Europe/London",
});
const {
data: { schedulesToShow },
} = useSettings();

useEffect(() => {
const [classes, schedule] = [
Expand Down Expand Up @@ -71,7 +72,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]) {
Expand Down Expand Up @@ -138,9 +143,9 @@ const Home = () => {
{/* Schedule UI */}
<section
id="Schedule"
className="flex grow flex-col md:flex-row lg:ml-10 lg:flex-col"
className="flex grow flex-col md:flex-row lg:ml-10 lg:flex-col max-lg:"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you add max-lg here

>
{schedules.map((schedule, index) => (
{schedules.slice(0, 2).map((schedule, index) => (
<div key={index} className="w-full md:mr-4 lg:mr-0">
<h2 className="title mr-2">
{dateFormat.format(schedule.date)}
Expand All @@ -153,6 +158,37 @@ const Home = () => {
/>
</div>
))}
{schedules.length > 2 && !showMoreSchedules && (
<Button
className="justify-center max-lg:hidden"
onClick={() => setShowMoreSchedules(true)}
>
Show More Schedules
</Button>
)}
{showMoreSchedules && (
<div className="max-lg:hidden">
{schedules.slice(2).map((schedule, index) => (
<div key={index} className="w-full md:mr-4 lg:mr-0">
<h2 className="title mr-2">
{dateFormat.format(schedule.date)}
</h2>

<ScheduleComponent
classes={classes}
schedule={schedule.schedule}
loading={loading}
/>
</div>
))}
<Button
className="justify-center"
onClick={() => setShowMoreSchedules(false)}
>
Show Fewer Schedules
</Button>
</div>
)}
Comment on lines +161 to +191
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple issues with this button:

  • it disappears on smaller screen sizes
  • if you select more than 2 schedules in settings, this button appears. If I'm a student and want to see 3 schedules on my homescreen, why would I want to have to click this every single time

let's remove this for now, or at least find a better way to implement it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that's what you wanted....

k. should have been draft though, ur right

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, my bad. probably should've discussed this one more

</section>
</div>
{Array.isArray(classes) &&
Expand Down
Loading