Skip to content

Commit

Permalink
Organize directory structure. Continue address code analysis comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCarlino committed Feb 25, 2024
1 parent e446968 commit 855526e
Show file tree
Hide file tree
Showing 54 changed files with 74 additions and 76 deletions.
2 changes: 1 addition & 1 deletion server/auth-helpers.ts → koala/auth-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { errorReport } from "@/utils/error-report";
import { errorReport } from "@/koala/error-report";
import { prismaClient } from "./prisma-client";

type UserID = number | string | undefined | null;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/fetch-lesson.ts → koala/fetch-lesson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { existsSync, mkdir, readFileSync, writeFileSync } from "fs";
import path from "path";
import { draw, map, template } from "radash";
import { errorReport } from "./error-report";
import { prismaClient } from "@/server/prisma-client";
import { prismaClient } from "@/koala/prisma-client";
import { Card } from "@prisma/client";

type LessonType = "listening" | "speaking";
Expand Down
2 changes: 1 addition & 1 deletion utils/get-card-or-fail.ts → koala/get-card-or-fail.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prismaClient } from "@/server/prisma-client";
import { prismaClient } from "@/koala/prisma-client";
import { errorReport } from "./error-report";

export async function getCardOrFail(id: number, userId?: string) {
Expand Down
2 changes: 1 addition & 1 deletion utils/is-approved-user.ts → koala/is-approved-user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prismaClient } from "@/server/prisma-client";
import { prismaClient } from "@/koala/prisma-client";

// Users that are allowed to use GPT-4, etc..
export const superUsers = (process.env.AUTHORIZED_EMAILS || "")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { errorReport } from "@/utils/error-report";
import { errorReport } from "@/koala/error-report";
import { listening } from "./listening";
import { speaking } from "./speaking";
import { QuizEvaluator } from "./types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { template } from "radash";
import { QuizEvaluator } from "./types";
import { yesOrNo } from "@/utils/openai";
import { yesOrNo } from "@/koala/openai";

const PROMPT = `
Sentence B: "{{term}}" ({{langCode}})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { YesOrNo, yesOrNo } from "@/utils/openai";
import { YesOrNo, yesOrNo } from "@/koala/openai";
import { QuizEvaluator } from "./types";
import { template } from "radash";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { prismaClient } from "../prisma-client";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";

export const bulkCreateCards = procedure
.input(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { z } from "zod";
import { prismaClient } from "../prisma-client";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { getUserSettings } from "../auth-helpers";
import { errorReport } from "@/utils/error-report";
import { errorReport } from "@/koala/error-report";

export const deleteCard = procedure
.input(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { getUserSettings } from "../auth-helpers";
import { prismaClient } from "../prisma-client";

Expand Down
4 changes: 2 additions & 2 deletions server/routers/edit-card.ts → koala/routers/edit-card.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { z } from "zod";
import { prismaClient } from "../prisma-client";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { getUserSettings } from "../auth-helpers";
import { errorReport } from "@/utils/error-report";
import { errorReport } from "@/koala/error-report";

export const editCard = procedure
.input(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { z } from "zod";
import { prismaClient } from "../prisma-client";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { getUserSettings } from "../auth-helpers";
import { errorReport } from "@/utils/error-report";
import { errorReport } from "@/koala/error-report";

export const editUserSettings = procedure
.input(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { BACKUP_SCHEMA } from "@/pages/cards";

export const exportCards = procedure
Expand Down
2 changes: 1 addition & 1 deletion server/routers/faucet.ts → koala/routers/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { getUserSettings } from "../auth-helpers";

/** The `faucet` route is a mutation that returns a "Hello, world" string
Expand Down
4 changes: 2 additions & 2 deletions server/routers/flag-card.ts → koala/routers/flag-card.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { prismaClient } from "../prisma-client";
import { procedure } from "../trpc";
import { getCardOrFail } from "@/utils/get-card-or-fail";
import { procedure } from "../trpc-procedure";
import { getCardOrFail } from "@/koala/get-card-or-fail";

export const flagCard = procedure
.input(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { prismaClient } from "../prisma-client";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";

export const getAllCards = procedure
.input(z.object({}))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { procedure } from "../trpc";
import getLessons from "@/utils/fetch-lesson";
import { procedure } from "../trpc-procedure";
import getLessons from "@/koala/fetch-lesson";
import { getUserSettings } from "../auth-helpers";
import { prismaClient } from "../prisma-client";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { procedure } from "../trpc";
import { getCardOrFail } from "@/utils/get-card-or-fail";
import { procedure } from "../trpc-procedure";
import { getCardOrFail } from "@/koala/get-card-or-fail";

export const getOneCard = procedure
.input(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { getUserSettings as gus } from "../auth-helpers";

export const getUserSettings = procedure
Expand Down
4 changes: 2 additions & 2 deletions server/routers/grade-quiz.ts → koala/routers/grade-quiz.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { z } from "zod";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { prismaClient } from "../prisma-client";
import { getQuizEvaluator } from "../quiz-evaluators";
import { transcribeB64 } from "@/utils/transcribe";
import { transcribeB64 } from "@/koala/transcribe";
import { QuizEvaluatorOutput } from "../quiz-evaluators/types";
import { Grade } from "femto-fsrs";
import { calculateSchedulingData, setGrade } from "./import-cards";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { z } from "zod";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { OLD_BACKUP_SCHEMA } from "@/pages/cards";
import { Grade, createDeck } from "femto-fsrs";
import { prismaClient } from "../prisma-client";
import { getUserSettings } from "../auth-helpers";
import { Quiz } from "@prisma/client";
import { timeUntil } from "@/utils/time-until";
import { timeUntil } from "@/koala/time-until";

type QuizGradingFields =
| "difficulty"
Expand Down
2 changes: 1 addition & 1 deletion server/routers/main.ts → koala/routers/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { router } from "../trpc";
import { router } from "../trpc-procedure";
import { bulkCreateCards } from "./bulk-create-cards";
import { deleteCard } from "./delete-card";
import { deleteFlaggedCards } from "./delete-flagged-card";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { errorReport } from "@/utils/error-report";
import { errorReport } from "@/koala/error-report";
import { z } from "zod";
import { getUserSettings } from "../auth-helpers";
import { prismaClient } from "../prisma-client";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";
import { setGrade } from "./import-cards";

export const manuallyGrade = procedure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createCardsFromText } from "@/utils/create-cards-from-text";
import { createCardsFromText } from "@/koala/create-cards-from-text";
import { z } from "zod";
import { procedure } from "../trpc";
import { procedure } from "../trpc-procedure";

export const parseCards = procedure
.input(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { errorReport } from "@/utils/error-report";
import { errorReport } from "@/koala/error-report";
import { z } from "zod";
import { getUserSettings } from "../auth-helpers";
import { prismaClient } from "../prisma-client";
import { procedure } from "../trpc";
import { timeUntil } from "@/utils/time-until";
import { procedure } from "../trpc-procedure";
import { timeUntil } from "@/koala/time-until";

export const rollbackGrade = procedure
.input(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trpc } from "@/utils/trpc";
import { trpc } from "@/koala/trpc-config";
import { Container, Grid, Center, Button } from "@mantine/core";
import { notifications } from "@mantine/notifications";
import { UserSettings } from "@prisma/client";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/trpc.ts → koala/trpc-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { httpBatchLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import type { AppRouter } from "../server/routers/main";
import type { AppRouter } from "./routers/main";
import superjson from "superjson";

function getBaseUrl() {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import "@mantine/core/styles.css";
import { AppProps } from "next/app";
import Head from "next/head";
import { MantineProvider } from "@mantine/core";
import { trpc } from "@/utils/trpc";
import { trpc } from "@/koala/trpc-config";
import { SessionProvider } from "next-auth/react";
import Navbar from "./_nav";
import { Notifications } from "@mantine/notifications";
import { UserSettingsProvider } from "@/components/settings-provider";
import { UserSettingsProvider } from "@/koala/settings-provider";

function App(props: AppProps) {
const { Component, pageProps } = props;
Expand Down
2 changes: 1 addition & 1 deletion pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prismaClient } from "@/server/prisma-client";
import { prismaClient } from "@/koala/prisma-client";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import NextAuth, { AuthOptions } from "next-auth";
import EmailProvider from "next-auth/providers/email";
Expand Down
4 changes: 2 additions & 2 deletions pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as trpcNext from "@trpc/server/adapters/next";
import { appRouter } from "../../../server/routers/main";
import { appRouter } from "../../../koala/routers/main";
import { getServerSession } from "next-auth";
import { authOptions } from "../auth/[...nextauth]";
import { prismaClient } from "@/server/prisma-client";
import { prismaClient } from "@/koala/prisma-client";

export default trpcNext.createNextApiHandler({
router: appRouter,
Expand Down
4 changes: 2 additions & 2 deletions pages/cards.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CardTable } from "@/components/card-table";
import { trpc } from "@/utils/trpc";
import { CardTable } from "@/koala/card-table";
import { trpc } from "@/koala/trpc-config";
import { Button, Container, FileButton } from "@mantine/core";
import { z } from "zod";

Expand Down
2 changes: 1 addition & 1 deletion pages/cards/[card_id].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trpc } from "@/utils/trpc";
import { trpc } from "@/koala/trpc-config";
import { Button, Checkbox, Container, Paper, TextInput } from "@mantine/core";
import { useForm } from "@mantine/form";
import { useRouter } from "next/router";
Expand Down
2 changes: 1 addition & 1 deletion pages/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Group,
TextInput,
} from "@mantine/core";
import { trpc } from "@/utils/trpc";
import { trpc } from "@/koala/trpc-config";
type ProcessedCard = {
term: string;
definition: string;
Expand Down
2 changes: 1 addition & 1 deletion pages/faucet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { trpc } from "@/utils/trpc";
import { trpc } from "@/koala/trpc-config";

/** The faucet component has a button that when clicked
* calls the "faucet" trpc mutation:
Expand Down
40 changes: 19 additions & 21 deletions pages/study.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import MicrophonePermissions from "@/components/microphone-permissions";
import { playAudio } from "@/components/play-audio";
import { QuizFailure, linkToEditPage } from "@/components/quiz-failure";
import { blobToBase64, convertBlobToWav } from "@/components/record-button";
import { useUserSettings } from "@/components/settings-provider";
import MicrophonePermissions from "@/koala/microphone-permissions";
import { playAudio } from "@/koala/play-audio";
import { QuizFailure, linkToEditPage } from "@/koala/quiz-failure";
import { blobToBase64, convertBlobToWav } from "@/koala/record-button";
import { useUserSettings } from "@/koala/settings-provider";
import {
Action,
Quiz,
State,
gotoNextQuiz,
newQuizState,
quizReducer,
} from "@/utils/study_reducer";
import { trpc } from "@/utils/trpc";
import { useVoiceRecorder } from "@/utils/use-recorder";
} from "@/koala/study_reducer";
import { trpc } from "@/koala/trpc-config";
import { useVoiceRecorder } from "@/koala/use-recorder";
import { Button, Container, Grid } from "@mantine/core";
import { useHotkeys } from "@mantine/hooks";
import { Grade } from "femto-fsrs";
Expand All @@ -35,6 +35,16 @@ type QuizViewProps = {
startRecording(grade: Grade): Promise<void>;
stopRecording: () => Promise<void>;
};
type StudyHeaderProps = {
lessonType: keyof typeof HEADER;
langCode: string;
};
type QuizAssertion = (q: Quiz | undefined) => asserts q is Quiz;
type HotkeyButtonProps = {
hotkey: string;
label: string;
onClick: () => void;
};

const HEADER_STYLES = {
display: "flex",
Expand All @@ -60,10 +70,7 @@ export const HOTKEYS: Record<string, string> = {
CONTINUE: "c",
};

type StudyHeaderProps = {
lessonType: keyof typeof HEADER;
langCode: string;
};
const GRID_SIZE = 2;

function StudyHeader({ lessonType, langCode }: StudyHeaderProps) {
const isSpeaking = lessonType === "speaking";
Expand All @@ -84,7 +91,6 @@ const currentQuiz = (state: State) => {
return curr.value;
};

type QuizAssertion = (q: Quiz | undefined) => asserts q is Quiz;
const assertQuiz: QuizAssertion = (q) => {
if (!q) {
throw new Error("No quiz found");
Expand Down Expand Up @@ -276,14 +282,6 @@ function NoQuizDue(_: {}) {
);
}

const GRID_SIZE = 2;

type HotkeyButtonProps = {
hotkey: string;
label: string;
onClick: () => void;
};

function HotkeyButton(props: HotkeyButtonProps) {
return (
<Grid.Col span={GRID_SIZE}>
Expand Down
Loading

0 comments on commit 855526e

Please sign in to comment.