Skip to content

Commit 27104bc

Browse files
committed
Refactor code for consistency and formatting
Standardized quote usage to single quotes, improved formatting, and cleaned up code style across multiple files. No functional changes were made; these updates enhance readability and maintain consistency throughout the codebase.
1 parent ae278aa commit 27104bc

File tree

11 files changed

+68
-93
lines changed

11 files changed

+68
-93
lines changed

src/app/(auth)/page.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import LoginButtons from '@src/components/LoginButtons';
2-
import { getServerAuthSession } from "@src/server/auth";
3-
import { redirect } from "next/navigation";
4-
5-
2+
import { getServerAuthSession } from '@src/server/auth';
3+
import { redirect } from 'next/navigation';
64

75
const Login = async () => {
86
const session = await getServerAuthSession();
97

108
// If logged in, go straight to homepage
119
if (session?.user) {
12-
redirect("/homepage");
10+
redirect('/homepage');
1311
}
14-
12+
1513
return (
16-
<main className="min-h-screen flex flex-col items-center justify-center gap-6">
14+
<main className="flex min-h-screen flex-col items-center justify-center gap-6">
1715
<h1 className="text-3xl font-bold text-white">UTD Notebook</h1>
1816
<p className="text-white">Sign in to continue</p>
1917

src/app/(main)/homepage/page.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ export const metadata: Metadata = {
88
};
99

1010
const Home = async () => {
11-
const session = await getServerAuthSession();
11+
const session = await getServerAuthSession();
1212

13-
// If not logged in, go to login page
14-
if (!session?.user) {
15-
redirect("/");
16-
}
17-
return (
18-
<>
19-
</>
20-
);
13+
// If not logged in, go to login page
14+
if (!session?.user) {
15+
redirect('/');
16+
}
17+
return <></>;
2118
};
2219

2320
export default Home;

src/app/(main)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// src/app/(main)/layout.tsx
2-
import type { ReactNode } from "react";
2+
import type { ReactNode } from 'react';
33
import NavBar from '@src/components/NavBar';
44

55
export default function MainLayout({ children }: { children: ReactNode }) {

src/app/(main)/uploadNotes/uploadNotes.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
} from '@mui/material';
1212
import { useRouter } from 'next/navigation';
1313
export default function UploadNoteForm() {
14-
1514
const router = useRouter();
1615
const [file, setFile] = useState<File | null>(null);
1716
const [prefix, setPrefix] = useState('');

src/app/AuthProvider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"use client";
1+
'use client';
22

3-
import { SessionProvider } from "next-auth/react";
4-
import type { ReactNode } from "react";
3+
import { SessionProvider } from 'next-auth/react';
4+
import type { ReactNode } from 'react';
55

66
export function AuthProvider({ children }: { children: ReactNode }) {
77
return <SessionProvider>{children}</SessionProvider>;

src/app/api/files/upload/route.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const uploadFormSchema = z.object({
1515
prefix: z.string().min(1, { message: 'Prefix is missing' }),
1616
courseNumber: z.string().min(1, { message: 'Course number is missing' }),
1717
sectionCode: z.string().min(1, { message: 'Section code is missing' }),
18-
professor: z.string().min(1 , { message: 'Professor is missing' }),
18+
professor: z.string().min(1, { message: 'Professor is missing' }),
1919
term: z.enum(['Spring', 'Summer', 'Fall']),
20-
year: z.coerce.number({ message: 'Year is missing'}),
21-
})
20+
year: z.coerce.number({ message: 'Year is missing' }),
21+
});
2222

2323
// Upload file to database w/ file metadata (Local)
2424
export async function POST(req: Request) {
@@ -42,17 +42,11 @@ export async function POST(req: Request) {
4242
const newFile = data.file as File;
4343

4444
if (!(newFile instanceof File)) {
45-
return NextResponse.json(
46-
{ error: 'Invalid file upload' },
47-
{ status: 400 },
48-
);
45+
return NextResponse.json({ error: 'Invalid file upload' }, { status: 400 });
4946
}
50-
47+
5148
if (newFile.size === 0) {
52-
return NextResponse.json(
53-
{ error: 'File is empty' },
54-
{ status: 400 },
55-
);
49+
return NextResponse.json({ error: 'File is empty' }, { status: 400 });
5650
}
5751

5852
if (!allowedTypes.includes(newFile.type)) {
@@ -76,10 +70,7 @@ export async function POST(req: Request) {
7670
});
7771

7872
if (!sectionData) {
79-
return NextResponse.json(
80-
{ error: 'Section not found' },
81-
{ status: 404 },
82-
);
73+
return NextResponse.json({ error: 'Section not found' }, { status: 404 });
8374
}
8475

8576
try {
@@ -96,10 +87,10 @@ export async function POST(req: Request) {
9687
const fileMetadata = {
9788
authorId: session.user.id,
9889
sectionId: sectionData.id,
99-
fileTitle: newFile.name, // required by schema
100-
fileName: newFile.name, // required by schema
90+
fileTitle: newFile.name, // required by schema
91+
fileName: newFile.name, // required by schema
10192
};
102-
93+
10394
const result = await db.insert(file).values(fileMetadata).returning();
10495

10596
return NextResponse.json(
@@ -108,9 +99,6 @@ export async function POST(req: Request) {
10899
);
109100
} catch (err) {
110101
console.error('File upload error:', err);
111-
return NextResponse.json(
112-
{ error: 'File upload failed' },
113-
{ status: 500 },
114-
);
102+
return NextResponse.json({ error: 'File upload failed' }, { status: 500 });
115103
}
116104
}

src/app/layout.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ export default function RootLayout({
5959
<AuthProvider>
6060
<AppRouterCacheProvider>
6161
<ThemeProvider theme={theme}>
62-
<ToastProvider>
63-
{children}
64-
</ToastProvider>
62+
<ToastProvider>{children}</ToastProvider>
6563
</ThemeProvider>
6664
</AppRouterCacheProvider>
6765
</AuthProvider>

src/components/LoginButtons.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
"use client";
1+
'use client';
22

3-
import { signIn, signOut, useSession } from "next-auth/react";
4-
import { Button, Stack, Typography } from "@mui/material";
3+
import { signIn, signOut, useSession } from 'next-auth/react';
4+
import { Button, Stack, Typography } from '@mui/material';
55

66
export default function LoginButtons() {
77
const { data: session, status } = useSession();
88

9-
if (status === "loading") {
9+
if (status === 'loading') {
1010
return <Typography color="white">Loading...</Typography>;
1111
}
1212

@@ -33,13 +33,13 @@ export default function LoginButtons() {
3333
<Stack spacing={2}>
3434
<Button
3535
variant="contained"
36-
onClick={() => void signIn("google", {callbackUrl: "/homepage"}) }
36+
onClick={() => void signIn('google', { callbackUrl: '/homepage' })}
3737
>
3838
Continue with Google
3939
</Button>
4040
<Button
4141
variant="outlined"
42-
onClick={() => void signIn("discord", {callbackUrl: "/homepage"})}
42+
onClick={() => void signIn('discord', { callbackUrl: '/homepage' })}
4343
>
4444
Continue with Discord
4545
</Button>

src/components/NavBar.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"use client";
1+
'use client';
22

33
import React from 'react';
44
import Link from 'next/link';
55
import Image from 'next/image';
66
import { IconButton, Tooltip } from '@mui/material';
7-
import { signOut } from "next-auth/react";
7+
import { signOut } from 'next-auth/react';
88

99
export default function NavBar() {
1010
return (
@@ -23,12 +23,12 @@ export default function NavBar() {
2323
>
2424
UTD Notebook
2525
</Link>
26-
<button
27-
onClick={() => void signOut({ callbackUrl: "/" })}
28-
className="bg-red-500 text-white px-3 py-2 rounded"
29-
>
30-
Sign Out
31-
</button>
26+
<button
27+
onClick={() => void signOut({ callbackUrl: '/' })}
28+
className="rounded bg-red-500 px-3 py-2 text-white"
29+
>
30+
Sign Out
31+
</button>
3232
<div className="ml-auto flex items-center gap-x-2 md:gap-x-4">
3333
<Tooltip title="Profile">
3434
<IconButton size="medium" href="/profile">

src/server/db/schema/file.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,21 @@ export const file = pgTable(
2525
.notNull()
2626
.references(() => user.id, { onDelete: 'cascade' }), // Could be 'set null' too, depending on what we want to do with it.
2727

28-
sectionId: varchar('section_id', { length: 6 })
29-
.references(() => section.id, { onDelete: 'set null' }),
28+
sectionId: varchar('section_id', { length: 6 }).references(
29+
() => section.id,
30+
{ onDelete: 'set null' },
31+
),
3032

31-
fileTitle: text('file_title')
32-
.notNull(),
33+
fileTitle: text('file_title').notNull(),
3334

34-
fileName: text('file_name')
35-
.notNull(),
35+
fileName: text('file_name').notNull(),
3636

3737
publishDate: timestamp('publish_date', { withTimezone: true })
3838
.notNull()
3939
.defaultNow(),
4040

41-
likes: integer('likes')
42-
.notNull()
43-
.default(0),
44-
saves: integer('saves')
45-
.notNull()
46-
.default(0),
41+
likes: integer('likes').notNull().default(0),
42+
saves: integer('saves').notNull().default(0),
4743

4844
// Edit flag for future workflows
4945
edited: boolean('edited').notNull().default(false),
@@ -55,7 +51,7 @@ export const file = pgTable(
5551
.notNull()
5652
.defaultNow(),
5753
},
58-
(t) => ([
54+
(t) => [
5955
// REVIEW: This is CASE SENSITIVE. File != file similar to Linux.
6056
// So a user could have "Lecture 1 Notes" and "lecture 1 notes".
6157
// I would recommend adding a PG extension for to support insensitivity.
@@ -66,7 +62,7 @@ export const file = pgTable(
6662

6763
check('file_likes_nonneg', sql`${t.likes} >= 0`),
6864
check('file_saves_nonneg', sql`${t.saves} >= 0`),
69-
]),
65+
],
7066
);
7167

7268
export const fileRelations = relations(file, ({ one }) => ({
@@ -78,4 +74,4 @@ export const fileRelations = relations(file, ({ one }) => ({
7874
fields: [file.sectionId],
7975
references: [section.id],
8076
}),
81-
}));
77+
}));

0 commit comments

Comments
 (0)