Skip to content

Commit f07f124

Browse files
authored
Chore/repo cleanup (#266)
Looking over this repo there are areas where I feel its a bit messy. Trying to clean this up, @jakemackie how would you clean this up?
2 parents 80d03af + a6dcc8a commit f07f124

File tree

67 files changed

+159
-322
lines changed

Some content is hidden

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

67 files changed

+159
-322
lines changed

src/actions/roadmap/ai/generate.ts renamed to src/actions/ai/generate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { prisma } from '@/utils/prisma';
33
import { generateDataForAi } from './get-question-data-for-gen';
44
import { addUidsToResponse } from './utils/add-uids-to-response';
55
import { addOrderToResponseQuestions } from './utils/add-order-to-response-questions';
6-
import { fetchRoadmapQuestions } from '../questions/fetch-roadmap-questiosn';
6+
import { fetchRoadmapQuestions } from '@/actions/roadmap/questions/fetch-roadmap-questions';
77
import { generateRoadmapResponse } from './utils/generate-question';
88
import { revalidateTag } from 'next/cache';
99

File renamed without changes.

src/actions/questions/admin/clear.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use server';
2-
import { userAuth } from '@/actions/utils/user-auth';
2+
import { userAuth } from '@/actions/questions/admin/utils/user-auth';
33
import { prisma } from '@/utils/prisma';
44

55
export const clearQuestionsForAdmin = async (uid: string) => {
@@ -13,8 +13,8 @@ export const clearQuestionsForAdmin = async (uid: string) => {
1313
// clear all questions that relate to the uid that was passed in
1414
await prisma.answers.deleteMany({
1515
where: {
16-
questionUid: uid,
17-
},
16+
questionUid: uid
17+
}
1818
});
1919

2020
return { success: true };

src/actions/questions/admin/list.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use server';
22
import { prisma } from '@/utils/prisma';
33
import { revalidateTag } from 'next/cache';
4-
import { userAuth } from '@/actions/utils/user-auth';
4+
import { userAuth } from '@/actions/questions/admin/utils/user-auth';
55

66
type GetQuestionsOpts = { from: number; to: number };
77

@@ -20,11 +20,11 @@ export const getQuestions = async (opts: GetQuestionsOpts) => {
2020
skip: from,
2121
take: to,
2222
orderBy: {
23-
questionDate: 'asc',
23+
questionDate: 'asc'
2424
},
2525
include: {
26-
answers: true,
27-
},
26+
answers: true
27+
}
2828
});
2929

3030
// revalidate the 'questions' tag
@@ -37,7 +37,7 @@ export const getQuestions = async (opts: GetQuestionsOpts) => {
3737
const {
3838
today: todayQuestions,
3939
future: futureQuestions,
40-
past: pastQuestions,
40+
past: pastQuestions
4141
} = res.reduce(
4242
(acc, question) => {
4343
const questionDate = new Date(question.questionDate);
@@ -60,7 +60,7 @@ export const getQuestions = async (opts: GetQuestionsOpts) => {
6060
return {
6161
today: todayQuestions,
6262
future: futureQuestions,
63-
past: pastQuestions,
63+
past: pastQuestions
6464
};
6565
} catch (error) {
6666
console.error('Failed to get questions:', error);

src/actions/questions/get-suggestions.ts

+23-23
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import { prisma } from '@/utils/prisma';
44
import {
55
extractTagIds,
6-
getTagsFromQuestion,
7-
} from '../utils/get-tags-from-question';
6+
getTagsFromQuestion
7+
} from './utils/get-tags-from-question';
88
import type {
99
QuestionWithoutAnswers,
10-
QuestionWithTags,
10+
QuestionWithTags
1111
} from '@/types/Questions';
1212
import { cache } from 'react';
1313

@@ -31,15 +31,15 @@ export const getSuggestions = cache(
3131
include: {
3232
tags: {
3333
include: {
34-
tag: true,
35-
},
36-
},
37-
},
38-
},
34+
tag: true
35+
}
36+
}
37+
}
38+
}
3939
},
4040
orderBy: {
41-
createdAt: 'desc',
42-
},
41+
createdAt: 'desc'
42+
}
4343
});
4444

4545
if (!userAnswers.length) {
@@ -87,28 +87,28 @@ export const getSuggestions = cache(
8787
some: {
8888
tag: {
8989
uid: {
90-
in: tagIds,
91-
},
92-
},
93-
},
94-
},
90+
in: tagIds
91+
}
92+
}
93+
}
94+
}
9595
},
9696
{
97-
dailyQuestion: true,
98-
},
99-
],
97+
dailyQuestion: true
98+
}
99+
]
100100
},
101101
include: {
102102
tags: {
103103
include: {
104-
tag: true,
105-
},
106-
},
104+
tag: true
105+
}
106+
}
107107
},
108108
orderBy: {
109-
createdAt: 'desc',
109+
createdAt: 'desc'
110110
},
111-
take: limit,
111+
take: limit
112112
});
113113

114114
// console.log('Found suggestions:', suggestions.length);

src/actions/questions/get-today.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use server';
22
import { Question } from '@/types/Questions';
33
import { prisma } from '@/utils/prisma';
4-
import { getTagsFromQuestion } from '../utils/get-tags-from-question';
4+
import { getTagsFromQuestion } from './utils/get-tags-from-question';
55

66
export const getTodaysQuestion = async (): Promise<Question | null> => {
77
try {
@@ -11,16 +11,16 @@ export const getTodaysQuestion = async (): Promise<Question | null> => {
1111
// Find a question where `questionDate` is today
1212
const res = await prisma.questions.findFirst({
1313
where: {
14-
questionDate: todayStart,
14+
questionDate: todayStart
1515
},
1616
include: {
1717
answers: true,
1818
tags: {
1919
include: {
20-
tag: true,
21-
},
22-
},
23-
},
20+
tag: true
21+
}
22+
}
23+
}
2424
});
2525

2626
if (!res) {

src/actions/questions/get-yesterdays-question.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use server';
22
import { Question } from '@/types/Questions';
33
import { prisma } from '@/utils/prisma';
4-
import { getTagsFromQuestion } from '../utils/get-tags-from-question';
4+
import { getTagsFromQuestion } from './utils/get-tags-from-question';
55

66
export const getYesterdaysQuestion = async (): Promise<Question | null> => {
77
try {
@@ -14,20 +14,20 @@ export const getYesterdaysQuestion = async (): Promise<Question | null> => {
1414
// Find a question where `questionDate` is yesterday
1515
const res = await prisma.questions.findFirst({
1616
where: {
17-
questionDate: yesterdayISOString,
17+
questionDate: yesterdayISOString
1818
},
1919
include: {
2020
answers: true,
2121
tags: {
2222
include: {
23-
tag: true,
24-
},
25-
},
26-
},
23+
tag: true
24+
}
25+
}
26+
}
2727
});
2828

2929
console.log({
30-
res,
30+
res
3131
});
3232

3333
if (!res) {

src/actions/questions/get.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use server';
22
import { prisma } from '@/utils/prisma';
3-
import { getTagsFromQuestion } from '../utils/get-tags-from-question';
3+
import { getTagsFromQuestion } from './utils/get-tags-from-question';
44
import { Question } from '@/types/Questions';
55

66
export const getQuestion = async (uid: string) => {
@@ -12,16 +12,16 @@ export const getQuestion = async (uid: string) => {
1212
try {
1313
const res = await prisma.questions.findUnique({
1414
where: {
15-
uid,
15+
uid
1616
},
1717
include: {
1818
answers: true,
1919
tags: {
2020
include: {
21-
tag: true,
22-
},
23-
},
24-
},
21+
tag: true
22+
}
23+
}
24+
}
2525
});
2626

2727
if (!res) {

src/actions/questions/list.ts

+24-25
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import { prisma } from '@/utils/prisma';
33
import type {
44
QuestionDifficulty,
5-
QuestionWithoutAnswers,
5+
QuestionWithoutAnswers
66
} from '@/types/Questions';
7-
import { getTagsFromQuestion } from '../utils/get-tags-from-question';
7+
import { getTagsFromQuestion } from './utils/get-tags-from-question';
88
import { QuestionFilters } from '@/types/Filters';
99

1010
type ListQuestionsReturnType = {
@@ -35,27 +35,26 @@ export const listQuestions = async (
3535
AND: [
3636
filters?.difficulty
3737
? {
38-
difficulty:
39-
filters.difficulty.toUpperCase() as QuestionDifficulty,
38+
difficulty: filters.difficulty.toUpperCase() as QuestionDifficulty
4039
}
4140
: {},
4241
filters?.completed === true
4342
? {
4443
userAnswers: {
4544
some: {
4645
// Check if there are answers by the current user
47-
userUid,
48-
},
49-
},
46+
userUid
47+
}
48+
}
5049
}
5150
: filters?.completed === false
5251
? {
5352
userAnswers: {
5453
none: {
5554
// Exclude questions answered by the current user
56-
userUid,
57-
},
58-
},
55+
userUid
56+
}
57+
}
5958
}
6059
: {},
6160
filters?.tags?.length
@@ -64,32 +63,32 @@ export const listQuestions = async (
6463
some: {
6564
tag: {
6665
name: {
67-
in: filters.tags,
68-
},
69-
},
70-
},
71-
},
66+
in: filters.tags
67+
}
68+
}
69+
}
70+
}
7271
}
73-
: {},
74-
],
75-
},
72+
: {}
73+
]
74+
}
7675
};
7776

7877
// fetch the paginated questions
7978
const questions = await prisma.questions.findMany({
8079
skip,
8180
take: pageSize,
8281
orderBy: {
83-
questionDate: filters?.ascending ? 'asc' : 'desc',
82+
questionDate: filters?.ascending ? 'asc' : 'desc'
8483
},
8584
...whereClause,
8685
include: {
8786
tags: {
8887
include: {
89-
tag: true,
90-
},
91-
},
92-
},
88+
tag: true
89+
}
90+
}
91+
}
9392
});
9493

9594
// transform the questions to match the expected format
@@ -99,14 +98,14 @@ export const listQuestions = async (
9998

10099
// fetch the total number of matching questions (without pagination)
101100
const total = await prisma.questions.count({
102-
where: whereClause.where,
101+
where: whereClause.where
103102
});
104103

105104
return {
106105
questions: transformedQuestions,
107106
total,
108107
page,
109108
pageSize,
110-
totalPages: Math.ceil(total / pageSize),
109+
totalPages: Math.ceil(total / pageSize)
111110
};
112111
};
File renamed without changes.

src/app/(dashboard)/(default_layout)/layout.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import BackToDashboard from '@/components/global/back-to-dashboard';
2-
import CurrentStreak from '@/components/global/current-streak';
3-
import Feedback from '@/components/global/feedback-button';
1+
import BackToDashboard from '@/components/ui/back-to-dashboard';
2+
import CurrentStreak from '@/components/ui/current-streak';
3+
import Feedback from '@/components/ui/feedback-button';
44
import { Separator } from '@/components/ui/separator';
55

66
export default function StatisticsLayout({

src/app/(dashboard)/(questions)/question/[uid]/layout.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { getQuestion } from '@/actions/questions/get';
22
import { getRandomQuestion } from '@/actions/questions/get-next-question';
3-
import BackToDashboard from '@/components/global/back-to-dashboard';
4-
import CurrentStreak from '@/components/global/current-streak';
3+
import BackToDashboard from '@/components/ui/back-to-dashboard';
4+
import CurrentStreak from '@/components/ui/current-streak';
55
import QuestionNavigation from '@/components/global/navigation/question-navigation';
66
import { Separator } from '@/components/ui/separator';
77
import { useUserServer } from '@/hooks/useUserServer';
88

99
export default async function QuestionUidLayout({
1010
children,
11-
params,
11+
params
1212
}: Readonly<{ children: React.ReactNode; params: { uid: string } }>) {
1313
const { uid } = params;
1414

@@ -18,7 +18,7 @@ export default async function QuestionUidLayout({
1818

1919
const nextQuestion = await getRandomQuestion({
2020
currentQuestionId: uid,
21-
userUid: user.uid,
21+
userUid: user.uid
2222
});
2323

2424
return (

0 commit comments

Comments
 (0)