Skip to content

Commit

Permalink
Revert "Refactored Everything to use supabase_server & client"
Browse files Browse the repository at this point in the history
This reverts commit 2a5ac8c.
  • Loading branch information
ImJustChew committed Nov 4, 2023
1 parent a2d2096 commit 42edbe8
Show file tree
Hide file tree
Showing 27 changed files with 45 additions and 239 deletions.
130 changes: 1 addition & 129 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@mui/material": "^5.14.14",
"@sentry/nextjs": "^7.74.1",
"@supabase/supabase-js": "^2.38.4",
"@types/jsonwebtoken": "^9.0.4",
"@types/node": "20.6.3",
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
Expand All @@ -34,7 +33,6 @@
"date-fns-tz": "^2.0.0",
"fuse.js": "^6.6.2",
"ics": "^3.5.0",
"jsonwebtoken": "^9.0.2",
"leaflet": "^1.9.4",
"negotiator": "^0.6.3",
"next": "13.5.6",
Expand Down
17 changes: 10 additions & 7 deletions src/app/[lang]/bus/bus/[busId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
'use client';;
'use client';
import Fade from '@/components/Animation/Fade';
import { getVehicleDescription, routes, stops } from '@/const/bus';
import GreenLineIcon from '@/components/BusIcons/GreenLineIcon';
import RedLineIcon from '@/components/BusIcons/RedLineIcon';
import supabase, { BusScheduleDefinition } from '@/config/supabase';
import { Route, Stop, getVehicleDescription, routes, stops } from '@/const/bus';
import useDictionary from '@/dictionaries/useDictionary';
import { useSettings } from '@/hooks/contexts/settings';
import { Button, Divider, LinearProgress } from '@mui/joy';
import { format } from 'date-fns';
import { useMemo } from 'react';
import { Button, Checkbox, Chip, Divider, LinearProgress } from '@mui/joy';
import { format, add, formatDistanceStrict } from 'date-fns';
import { useEffect, useState, useMemo } from 'react';
import { ChevronLeft, MapPin } from 'react-feather';
import useSWR from 'swr';
import NandaLineIcon from '@/components/BusIcons/NandaLineIcon';
import RouteIcon from '@/components/BusIcons/RouteIcon';
import useTime from '@/hooks/useTime';
import useSupabaseClient from '@/config/supabase_client';
type PageProps = {
params: { busId: string }
}

const BusStop = ({ params: { busId } }: PageProps) => {
const dict = useDictionary();
const supabase = useSupabaseClient();

const { language } = useSettings();
const { data: busSchedule, error, isLoading } = useSWR(['bus_schedule', busId], async ([table, busId]) => {
const { data: busses, error } = await supabase.from('bus_schedule').select('*').eq('id', busId);
Expand Down
4 changes: 1 addition & 3 deletions src/app/[lang]/bus/stop/[stopId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';;
import Fade from '@/components/Animation/Fade';
import supabase from '@/config/supabase';
import { ScheduleItem, busDays, getVehicleDescription, routes, stops } from '@/const/bus';
import useDictionary from '@/dictionaries/useDictionary';
import { useSettings } from '@/hooks/contexts/settings';
Expand All @@ -13,7 +14,6 @@ import useSWR from 'swr'
import RouteIcon from '@/components/BusIcons/RouteIcon';
import RoutesFilterChips from './RoutesFilterChips';
import useTime from '@/hooks/useTime';
import useSupabaseClient from '@/config/supabase_client';
import BusDelayAlert from '../../BusDelayAlert';
import BusDelayReportAlert from './BusDelayReportAlert';

Expand All @@ -24,8 +24,6 @@ type PageProps = {
const BusStop = ({ params: { stopId } }: PageProps) => {
const dict = useDictionary();
const { language } = useSettings();
const supabase = useSupabaseClient();

//update time every 30 seconds
const date = useTime();

Expand Down
3 changes: 1 addition & 2 deletions src/app/[lang]/cds/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use client';
import NTHUBirdIcon from "@/components/NTHUBirdIcon"
import CourseSearchbar from "@/components/Timetable/CourseSearchbar";
import Timetable from "@/components/Timetable/Timetable";
import getSupabaseServer from "@/config/supabase_server";
import supabase from "@/config/supabase";
import { Alert, Button, CircularProgress, DialogActions, DialogContent, Divider, Modal, ModalClose, ModalDialog } from "@mui/joy"
import { signIn, useSession } from "next-auth/react"
import { FC, useState } from "react"
Expand Down
1 change: 1 addition & 0 deletions src/app/[lang]/courses/[courseId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Fade from "@/components/Animation/Fade";
import supabase from "@/config/supabase";
import { getDictionary } from "@/dictionaries/dictionaries";
import {getCourse, getCoursePTTReview} from '@/lib/course';
import { LangProps } from "@/types/pages";
Expand Down
4 changes: 1 addition & 3 deletions src/app/[lang]/courses/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';;
import CourseListItem from "@/components/Courses/CourseListItem";
import InputControl from "@/components/FormComponents/InputControl";
import supabase, { CourseDefinition } from "@/config/supabase";
import { Button, CircularProgress, Divider, Drawer, IconButton, LinearProgress, Stack } from "@mui/joy";
import { NextPage } from "next";
import { useEffect, useState, Fragment, useRef, use, useMemo } from "react";
Expand All @@ -15,8 +16,6 @@ import { useRouter, useSearchParams } from "next/navigation";
import queryString from 'query-string';
import { GETargetCodes } from "@/const/ge_target";
import { departments } from "@/const/departments";
import useSupabaseClient from '@/config/supabase_client';
import { CourseDefinition } from "@/config/supabase.types";
import useUserTimetable from "@/hooks/useUserTimetable";

const emptyFilters: RefineControlFormTypes = {
Expand All @@ -37,7 +36,6 @@ const emptyFilters: RefineControlFormTypes = {

const CoursePage: NextPage = () => {
const dict = useDictionary();
const supabase = useSupabaseClient();
const [courses, setCourses] = useState<CourseDefinition[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const [totalCount, setTotalCount] = useState<number>(0);
Expand Down
6 changes: 2 additions & 4 deletions src/app/[lang]/timetable/calendar.ics/route.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import supabase from "@/config/supabase";
import { scheduleTimeSlots } from "@/const/timetable";
import { createTimetableFromCourses } from "@/helpers/timetable";
import { getHours, getMinutes, parse } from "date-fns";
import { differenceInMinutes, getHours, getMinutes, parse } from "date-fns";
import * as ics from 'ics';
import { NextResponse } from "next/server";
import { zonedTimeToUtc } from 'date-fns-tz'
import getSupabaseServer from "@/config/supabase_server";

export async function GET(request: Request) {
const { searchParams } = new URL(request.url)

const supabase = await getSupabaseServer();
const courses_ids = searchParams.get('semester_1121')?.split(',')!;
const theme = searchParams.get('theme') || 'tsinghuarian';

Expand Down
3 changes: 1 addition & 2 deletions src/app/[lang]/timetable/view/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import Timetable from "@/components/Timetable/Timetable";
import { NextPage } from "next";
import { useRouter } from "next/navigation";
import { useSearchParams } from 'next/navigation'
import supabase from "@/config/supabase";
import useSWR from "swr";
import { createTimetableFromCourses, timetableColors } from "@/helpers/timetable";
import useSupabaseClient from '@/config/supabase_client';
import { useSettings } from "@/hooks/contexts/settings";

const ViewTimetablePage: NextPage = () => {
const router = useRouter();
const searchParams = useSearchParams();
const supabase = useSupabaseClient();
const courseCodes = searchParams.get('semester_1121')?.split(',');
const { timetableTheme } = useSettings();

Expand Down
3 changes: 1 addition & 2 deletions src/app/[lang]/venues/[locationId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import supabase from '@/config/supabase'
import NTHUMap from '@/components/Venue/NTHUMap'
import {createTimetableFromCourses} from '@/helpers/timetable';
import Timetable from '@/components/Timetable/Timetable';
import { Suspense } from 'react';
import getSupabaseServer from '@/config/supabase_server';
type Props = {
params: {
locationId: string;
}
}

const getCoursesWithVenue = async (venueId: string) => {
const supabase = await getSupabaseServer();
const { data, error } = await supabase.from('courses').select('*').containedBy('venues', [venueId]);
if (error) throw error;
else return data;
Expand Down
19 changes: 2 additions & 17 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import NextAuth from "next-auth"
import { SupabaseAdapter } from "@auth/supabase-adapter"
import jwt from "jsonwebtoken"

const handler = NextAuth({
providers: [
Expand Down Expand Up @@ -32,22 +31,8 @@ const handler = NextAuth({
url: process.env.NEXT_PUBLIC_SUPABASE_URL!,
secret: process.env.SUPABASE_SERVICE_ROLE_KEY!,
}),
callbacks: {
async session({ session, user }) {
const signingSecret = process.env.SUPABASE_JWT_SECRET
if (signingSecret) {
const payload = {
aud: "authenticated",
exp: Math.floor(new Date(session.expires).getTime() / 1000),
sub: user.id,
email: user.email,
role: "authenticated",
}
session.supabaseAccessToken = jwt.sign(payload, signingSecret)
}
return session
},
}


})

export { handler as GET, handler as POST }
Expand Down
2 changes: 1 addition & 1 deletion src/components/Courses/CourseListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CourseDefinition } from '@/config/supabase.types';
import { CourseDefinition } from '@/config/supabase';
import useDictionary from '@/dictionaries/useDictionary';
import { useSettings } from '@/hooks/contexts/settings';
import { Button, Chip, Tooltip } from '@mui/joy';
Expand Down
Loading

0 comments on commit 42edbe8

Please sign in to comment.