Skip to content

Commit eec7993

Browse files
committed
Merge branch 'main' into feature/stats-page
2 parents 6e11f35 + 1c6bf49 commit eec7993

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1251
-320
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ We love to be transparent with our users, so below are the next features we have
2424
- **Social**: Profiles, friends/coworkers
2525
- **Statistics**: A more in-depth statistics dashboard, giving you a greater insight on your current ability.
2626
- **Multi-language support**: Currently we only support JavaScript. However, we are looking into: Python, Typescript, and GoLang for our first wave of other languages to support.
27+
- **Searching**: Implement elastic search to easily find questions that you want to answer🚀
2728

2829
## 🛠 Tech Stack
2930

30-
- **Frontend**: React + Next.js
31+
- **Frameworks**: React + Next.js (app router)
3132
- **Styling**: Tailwind CSS
3233
- **UI Components**: Shadcn/UI, aceternity, recharts
3334
- **Backend**: Supabase
3435
- **Payments**: Stripe
3536
- **Hosting**: Vercel
3637
- **ORM**: Prisma
38+
- **Data fetching**: Tanstack Query
39+
- **Short links**: Dub
3740

3841
### Installation
3942

package-lock.json

Lines changed: 93 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@number-flow/react": "^0.4.2",
2020
"@prisma/client": "^5.19.1",
2121
"@radix-ui/react-accordion": "^1.2.1",
22+
"@radix-ui/react-alert-dialog": "^1.1.2",
2223
"@radix-ui/react-avatar": "^1.1.1",
2324
"@radix-ui/react-checkbox": "^1.1.1",
2425
"@radix-ui/react-collapsible": "^1.1.1",
@@ -59,7 +60,7 @@
5960
"mini-svg-data-uri": "^1.4.4",
6061
"motion": "^11.12.0",
6162
"nanoid": "^5.0.8",
62-
"next": "14.2.9",
63+
"next": "14.2.10",
6364
"next-themes": "^0.3.0",
6465
"openai": "^4.73.0",
6566
"posthog-js": "^1.188.0",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- CreateTable
2+
CREATE TABLE "DemoAnswers" (
3+
"uid" TEXT NOT NULL,
4+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
5+
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
6+
"questionUid" TEXT NOT NULL,
7+
"correctAnswer" BOOLEAN NOT NULL DEFAULT false,
8+
"userAnswer" TEXT NOT NULL,
9+
"timeTaken" INTEGER,
10+
11+
CONSTRAINT "DemoAnswers_pkey" PRIMARY KEY ("uid")
12+
);
13+
14+
-- AddForeignKey
15+
ALTER TABLE "DemoAnswers" ADD CONSTRAINT "DemoAnswers_questionUid_fkey" FOREIGN KEY ("questionUid") REFERENCES "Questions"("uid") ON DELETE CASCADE ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ model Questions {
111111
tags QuestionTags[]
112112
113113
difficulty QuestionDifficulty @default(EASY)
114+
115+
DemoAnswers DemoAnswers[]
114116
}
115117

116118
model Tag {
@@ -156,6 +158,17 @@ model Answers {
156158
timeTaken Int?
157159
}
158160

161+
model DemoAnswers {
162+
uid String @id @default(cuid())
163+
createdAt DateTime @default(now())
164+
updatedAt DateTime @default(now())
165+
questionUid String
166+
question Questions @relation(fields: [questionUid], references: [uid], onDelete: Cascade, onUpdate: Cascade)
167+
correctAnswer Boolean @default(false)
168+
userAnswer String
169+
timeTaken Int?
170+
}
171+
159172
model Streaks {
160173
uid String @id @default(cuid())
161174
createdAt DateTime @default(now())
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use server';
2+
import { prisma } from '@/utils/prisma';
3+
4+
export const answerDailyQuestionDemo = async (opts: {
5+
questionUid: string;
6+
userAnswerUid: string;
7+
timeTaken: number;
8+
}) => {
9+
const { questionUid, userAnswerUid, timeTaken } = opts;
10+
11+
// get the question
12+
const question = await prisma.questions.findUnique({
13+
where: {
14+
uid: questionUid
15+
}
16+
});
17+
18+
// if the question does not exist, return null
19+
if (!question) {
20+
return null;
21+
}
22+
23+
// check if the user answer is correct
24+
const isCorrect = question.correctAnswer === userAnswerUid;
25+
26+
// add the answer to the database
27+
await prisma.demoAnswers.create({
28+
data: {
29+
questionUid,
30+
userAnswer: userAnswerUid,
31+
correctAnswer: isCorrect,
32+
timeTaken
33+
}
34+
});
35+
36+
// if the answer is correct, return true
37+
if (isCorrect) return true;
38+
39+
// if the answer is incorrect, return false
40+
return false;
41+
};

0 commit comments

Comments
 (0)