-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from RickCarlino/prod
Multiple Updates
- Loading branch information
Showing
20 changed files
with
1,055 additions
and
644 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { prismaClient } from "@/server/prisma-client"; | ||
import { cleanString } from "@/utils/clean-string"; | ||
import { GetServerSidePropsContext } from "next"; | ||
import { getSession } from "next-auth/react"; | ||
import React from "react"; | ||
|
||
export async function getServerSideProps(context: GetServerSidePropsContext) { | ||
const session = await getSession({ req: context.req }); | ||
const userID = | ||
"" + | ||
( | ||
await prismaClient.user.findUnique({ | ||
where: { email: session?.user?.email || "" }, | ||
}) | ||
)?.id || ""; | ||
const transcripts = ( | ||
await prismaClient.transcript.findMany({ | ||
where: { card: { userId: userID } }, | ||
orderBy: { | ||
recordedAt: "desc", | ||
}, | ||
include: { | ||
card: true, | ||
}, | ||
}) | ||
) | ||
.filter((t) => { | ||
return cleanString(t.value) !== cleanString(t.card.term); | ||
}) | ||
.map((t) => { | ||
return { | ||
id: t.id, | ||
grade: t.grade.toPrecision(1), | ||
value: t.value, | ||
term: t.card.term, | ||
}; | ||
}); | ||
// Pass the transcripts to the page via props | ||
return { props: { transcripts } }; | ||
} | ||
|
||
type Transcript = { | ||
id: number; | ||
grade: string; | ||
value: string; | ||
term: string; | ||
}; | ||
|
||
type Props = { | ||
transcripts: Transcript[]; | ||
}; | ||
|
||
const TranscriptsPage = ({ transcripts }: Props) => { | ||
return ( | ||
<div> | ||
<h1>Transcripts</h1> | ||
<p> | ||
<strong>NOTE:</strong> Only cards that are not an exact match are | ||
displayed here. | ||
</p> | ||
<hr /> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Grade</th> | ||
<th>Phrase</th> | ||
<th>What You Said</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{transcripts.map((transcript) => ( | ||
<tr key={transcript.id}> | ||
<td>{transcript.grade}</td> | ||
<td>{transcript.term}</td> | ||
<td>{transcript.value}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TranscriptsPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,68 @@ | ||
import { prismaClient } from "@/server/prisma-client"; | ||
import { Container } from "@mantine/core"; | ||
import { GetServerSidePropsContext } from "next"; | ||
import { getSession } from "next-auth/react"; | ||
import Authed from "../components/authed"; | ||
import { UserSettings } from "@prisma/client"; | ||
|
||
export default function User() { | ||
export async function getServerSideProps(context: GetServerSidePropsContext) { | ||
const session = await getSession({ req: context.req }); | ||
const userId = | ||
"" + | ||
( | ||
await prismaClient.user.findUnique({ | ||
where: { email: session?.user?.email || "" }, | ||
}) | ||
)?.id; | ||
if (!userId) { | ||
throw new Error("User not found"); | ||
} | ||
|
||
const userSettings = await prismaClient.userSettings.upsert({ | ||
where: { userId: userId }, | ||
update: {}, | ||
create: { userId }, | ||
}); | ||
// Pass the transcripts to the page via props | ||
return { props: { userSettings: JSON.parse(JSON.stringify(userSettings)) } }; | ||
} | ||
|
||
type SettingsDisplayProps<T extends keyof UserSettings> = { | ||
setting: T; | ||
description: string; | ||
value: UserSettings[T]; | ||
}; | ||
|
||
function SettingsDisplay<T extends keyof UserSettings>( | ||
props: SettingsDisplayProps<T>, | ||
) { | ||
return ( | ||
<li> | ||
<label> | ||
{props.description} | ||
<input type="text" defaultValue={"" + props.value} /> | ||
</label> | ||
</li> | ||
); | ||
} | ||
|
||
type Props = { | ||
userSettings: UserSettings; | ||
}; | ||
|
||
export default function User(props: Props) { | ||
return Authed( | ||
<Container size="s"> | ||
<h1>User Settings</h1> | ||
<p> | ||
Eventually, I want this page to allow things like changing email | ||
address, changing password, and deleting account. It also needs stats on | ||
how much you have studied. | ||
</p> | ||
<h1>THIS DOESN'T WORK YET</h1> | ||
<ul> | ||
<SettingsDisplay | ||
setting={"playbackPercentage"} | ||
description={ | ||
"What percentage of recordings will be played back to you for review?" | ||
} | ||
value={props.userSettings.playbackPercentage} | ||
/> | ||
</ul> | ||
</Container>, | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20231108024642_add_transcript_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- CreateTable | ||
CREATE TABLE "Transcript" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"cardId" INTEGER NOT NULL, | ||
"transcript" TEXT NOT NULL, | ||
"recordedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"grade" REAL NOT NULL DEFAULT 0, | ||
CONSTRAINT "Transcript_cardId_fkey" FOREIGN KEY ("cardId") REFERENCES "Card" ("id") ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Transcript_cardId_key" ON "Transcript"("cardId"); |
23 changes: 23 additions & 0 deletions
23
prisma/migrations/20231108025629_rename_transcript_transcript_col/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `transcript` on the `Transcript` table. All the data in the column will be lost. | ||
- Added the required column `value` to the `Transcript` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- RedefineTables | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_Transcript" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"cardId" INTEGER NOT NULL, | ||
"value" TEXT NOT NULL, | ||
"recordedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"grade" REAL NOT NULL DEFAULT 0, | ||
CONSTRAINT "Transcript_cardId_fkey" FOREIGN KEY ("cardId") REFERENCES "Card" ("id") ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_Transcript" ("cardId", "grade", "id", "recordedAt") SELECT "cardId", "grade", "id", "recordedAt" FROM "Transcript"; | ||
DROP TABLE "Transcript"; | ||
ALTER TABLE "new_Transcript" RENAME TO "Transcript"; | ||
CREATE UNIQUE INDEX "Transcript_cardId_key" ON "Transcript"("cardId"); | ||
PRAGMA foreign_key_check; | ||
PRAGMA foreign_keys=ON; |
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20231111231008_add_user_settings_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- CreateTable | ||
CREATE TABLE "UserSettings" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"userId" TEXT NOT NULL, | ||
"playbackPercentage" REAL NOT NULL DEFAULT 1, | ||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" DATETIME NOT NULL, | ||
CONSTRAINT "UserSettings_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "UserSettings_userId_key" ON "UserSettings"("userId"); |
Oops, something went wrong.