Skip to content

Commit 3b48fe3

Browse files
committedMay 23, 2024
add takoboto scraping
1 parent 447b3c1 commit 3b48fe3

18 files changed

+95200
-3252
lines changed
 

‎.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ npm-debug.*
2424
yarn-debug.*
2525
yarn-error.*
2626

27+
.pnp.*
28+
.yarn/*
29+
!.yarn/patches
30+
!.yarn/plugins
31+
!.yarn/releases
32+
!.yarn/sdks
33+
!.yarn/versions
34+
2735
# macOS
2836
.DS_Store
2937
*.pem

‎.yarn/install-state.gz

-194 KB
Binary file not shown.

‎.yarn/releases/yarn-4.1.1.cjs

+893
Large diffs are not rendered by default.

‎.yarnrc

-5
This file was deleted.

‎.yarnrc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
nodeLinker: node-modules
2+
3+
yarnPath: .yarn/releases/yarn-4.1.1.cjs

‎.zed/settings.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22
//
33
// For a full list of overridable settings, and general information on folder-specific settings,
44
// see the documentation: https://zed.dev/docs/configuring-zed#folder-specific-settings
5-
{}
5+
{
6+
"lsp": {
7+
"pyright": {
8+
"initialization_options": {
9+
"python": {
10+
"pythonPath": "/Users/mmtf/miniforge3/bin/python"
11+
}
12+
}
13+
}
14+
}
15+
}

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This is a mobile application built with Expo and React Native that helps users p
1010
- Filtering questions by level and type
1111
- Review today's questions
1212
- Today's statistics
13+
- Randomizes answer order
1314
- Shirabe Jisho lookup (if installed)
1415
- [ ] Add more statistics
1516
- [x] Add question sets

‎app/(tabs)/_layout.tsx

-15
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,6 @@ export default function TabLayout() {
9191
tabBarIcon: ({ color }) => (
9292
<TabBarIcon name="question-circle" color={color} />
9393
),
94-
headerRight: () =>
95-
// reset db button for development
96-
__DEV__ && (
97-
<Button
98-
marginEnd="$2"
99-
icon={Delete}
100-
variant="outlined"
101-
color="red"
102-
theme="red_active"
103-
size="$2"
104-
onPress={resetAndReseed}
105-
>
106-
Reseed
107-
</Button>
108-
),
10994
}}
11095
/>
11196
<Tabs.Screen

‎app/(tabs)/question.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ function QuestionManager() {
6060
});
6161
return;
6262
}
63-
console.log(question.id);
6463

6564
setSolvedId((id) => id + 1);
6665
setQuestion(question);

‎app/(tabs)/settings.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import { answersTodayStore, settingsStore } from "@/services/store";
2020
import { MultipleSelectBox, SelectBox } from "../../components/SelectBox";
2121
import { PieChart } from "@/components/PieChart";
2222
import { useRouter } from "expo-router";
23+
import { Alert } from "react-native";
24+
import { resetAndReseed } from "../../components/SeedProvider";
25+
import { Delete } from "@tamagui/lucide-icons";
2326

2427
const levelItems: { name: Question["level"] }[] = [
2528
{ name: "N1" },
@@ -149,6 +152,30 @@ const SettingsTab: React.FC = () => {
149152
<Button onPress={() => router.push("/review")}>Review</Button>
150153
</YStack>
151154
)}
155+
<Button
156+
marginEnd="$2"
157+
icon={Delete}
158+
variant="outlined"
159+
color="red"
160+
theme="red_active"
161+
size="$2"
162+
onPress={() => {
163+
Alert.alert("Are You Sure?", "This may delete some questions", [
164+
{
165+
text: "Cancel",
166+
style: "cancel",
167+
},
168+
{
169+
text: "Reset",
170+
onPress: () => {
171+
resetAndReseed();
172+
},
173+
},
174+
]);
175+
}}
176+
>
177+
Reset Questions
178+
</Button>
152179
</YStack>
153180
);
154181
};

‎components/AnswerButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const AnswerButton = ({
2525
<Theme name="blue">
2626
<Button
2727
animation="superfastTransform"
28-
minWidth="40%"
28+
minWidth={answerText.length > 10 ? "90%" : "40%"}
2929
pressStyle={{ scale: 0.9 }}
3030
flex={1}
3131
theme={theme}

‎components/SeedProvider.tsx

+43-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { db } from "@/services/db"; // drizzle
2-
import { answers, categories, levels, questions } from "../db/schema";
2+
import {
3+
answers,
4+
categories,
5+
levels,
6+
questionSets,
7+
questions,
8+
} from "../db/schema";
39
import seedVals from "@/constants/seed.json";
410
import { useEffect, useState } from "react";
511
import { useAsyncStorage } from "@react-native-async-storage/async-storage";
@@ -8,38 +14,51 @@ import { getRandomQuestion } from "../services/questions";
814

915
const seed = async () => {
1016
try {
17+
const allValues = seedVals.questions.map(
18+
({
19+
id,
20+
questionText: question,
21+
answers,
22+
correctAnswer,
23+
level,
24+
category,
25+
questionSet,
26+
}) => ({
27+
id,
28+
question,
29+
answers,
30+
category: categories.includes(category as any)
31+
? (category as any)
32+
: "unknown",
33+
level: levels.includes(level as any) ? (level as any) : "N5",
34+
correctAnswer,
35+
questionSet,
36+
}),
37+
);
1138
console.log("Seeding database...");
12-
await db
13-
.insert(questions)
14-
.values(
15-
seedVals.questions.map(
16-
({
17-
questionText: question,
18-
answers,
19-
correctAnswer,
20-
level,
21-
category,
22-
}) => ({
23-
question,
24-
answers,
25-
category: categories.includes(category as any)
26-
? (category as any)
27-
: "unknown",
28-
level: levels.includes(level as any) ? (level as any) : "N5",
29-
correctAnswer,
30-
}),
31-
),
32-
)
33-
.execute();
39+
await db.insert(questionSets).values(seedVals.questionSets).execute();
40+
41+
// insert 1K questions at a time.
42+
for (let i = 0; i < allValues.length / 1000; i++) {
43+
await db
44+
.insert(questions)
45+
.values(allValues.slice(i * 1000, (i + 1) * 1000))
46+
.execute();
47+
}
3448
} catch (e) {
3549
console.error(e);
3650
}
3751
};
52+
3853
export const resetAndReseed = async () => {
3954
try {
40-
await db.delete(answers).execute();
55+
const answerObjects = await db.delete(answers).returning().execute();
4156
await db.delete(questions).execute();
57+
await db.delete(questionSets).execute();
4258
await seed();
59+
60+
// try to restore answers
61+
await db.insert(answers).values(answerObjects).execute();
4362
} catch (e) {
4463
console.error(e);
4564
}

0 commit comments

Comments
 (0)
Please sign in to comment.