Skip to content

Commit 39af506

Browse files
committed
fix build
1 parent 9d979d0 commit 39af506

File tree

4 files changed

+139
-3
lines changed

4 files changed

+139
-3
lines changed

.cursor/rules/ai-features.mdc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# AI-Assisted Features
7+
8+
This project incorporates AI to assist with deck and card creation/management.
9+
10+
## AI Deck Generation
11+
12+
- **Entry Point (UI)**: The page at `[app/deck/ai-generate/page.tsx](mdc:app/deck/ai-generate/page.tsx)` allows users to input a topic and generate a new deck with AI-suggested cards.
13+
- **Server Action**: The `createDeckWithAICardsAction` (expected in `app/actions/aiDecks.ts` or similar) handles the backend logic.
14+
- It takes a topic from the user.
15+
- Interacts with an AI service to generate card content (front/back text).
16+
- Creates a new deck and populates it with the generated cards.
17+
- **Relevant Types**:
18+
- `QuestionAnswerPair` from `[app/types.ts](mdc:app/types.ts)` might be used for the AI-generated card content.
19+
20+
## AI Card Editing (within a Deck)
21+
22+
- **Context**: On the deck overview page (`[app/deck/[deckId]/overview/page.tsx](mdc:app/deck/[deckId]/overview/page.tsx)`), users can initiate AI-assisted editing for the cards within that deck.
23+
- **Components**:
24+
- `AIEditPromptModal`: A modal component that likely takes user input or a prompt to guide the AI in suggesting card edits.
25+
- `AIEditReviewList`: A component to display the AI's suggestions for card modifications (creations, updates, deletions) and allow the user to accept or reject them.
26+
- **Server Actions**: (Specific actions for applying these AI edits are not detailed but would reside in server actions, possibly in `[app/actions/cards.ts](mdc:app/actions/cards.ts)` or a dedicated AI actions file.)
27+
- **Suggestion Types** (from `[app/types.ts](mdc:app/types.ts)`): These types define the structure of AI suggestions for modifying cards.
28+
- `AICreateCardSuggestion`: Suggests creating a new card.
29+
```typescript
30+
export interface AICreateCardSuggestion {
31+
type: 'create';
32+
front_text: string;
33+
back_text: string;
34+
extra_context?: string;
35+
}
36+
```
37+
- `AIUpdateCardSuggestion`: Suggests updating an existing card.
38+
```typescript
39+
export interface AIUpdateCardSuggestion {
40+
type: 'update';
41+
cardId: string;
42+
front_text?: string;
43+
back_text?: string;
44+
extra_context?: string;
45+
}
46+
```
47+
- `AIDeleteCardSuggestion`: Suggests deleting an existing card.
48+
```typescript
49+
export interface AIDeleteCardSuggestion {
50+
type: 'delete';
51+
cardId: string;
52+
}
53+
```
54+
- `AICardEditSuggestion`: A union type encompassing the above suggestions.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Card and Review Event Management
7+
8+
This rule details the server actions for managing cards and review events, primarily located in `[app/actions/cards.ts](mdc:app/actions/cards.ts)`, and their associated data structures defined in `[app/types.ts](mdc:app/types.ts)`.
9+
10+
## Core Card Operations
11+
12+
- **Creation**: `createCardAction` adds a new card to a specified deck.
13+
- Input: `deckId`, `frontText`, `backText`, `token`.
14+
- Output: `CreateCardResult` with the created `Card`.
15+
- **Fetching Single Card**: `getCardAction` retrieves a specific card by its ID.
16+
- Input: `cardId`, `token`.
17+
- Output: `FetchCardResult` with the `Card`.
18+
- **Fetching Deck Cards**: `fetchDeckCardsAction` retrieves all cards belonging to a specific deck.
19+
- Input: `deckId`.
20+
- Output: `FetchCardsResult` with an array of `Card`s.
21+
- **Updating**: `updateCardAction` modifies the front or back text of an existing card.
22+
- Input: `cardId`, `deckId`, `frontText?`, `backText?`, `token`.
23+
- Output: `UpdateCardResult` with the updated `Card`.
24+
- **Deletion**: `deleteCardAction` removes a card and its associated review events.
25+
- Input: `cardId`, `deckId`, `token`.
26+
- Output: `DeleteCardResult`.
27+
28+
## Card Review and Retrieval
29+
30+
- **Fetching Cards for Review**: `getCardsForReviewAction` retrieves cards for a review session.
31+
- Supports fetching from specific deck(s) or all decks.
32+
- Strategies: `random`, `missedFirst`.
33+
- Input: `GetCardsForReviewParams` (token, deckId?, deckIds?, limit, strategy).
34+
- Output: `FetchReviewCardsResult` with an array of `Card`s.
35+
- **Fetching Missed Cards**: `getMissedCardsForDeckInTimeframeAction` retrieves cards from a specific deck that were marked "MISSED" within a given timeframe.
36+
- Input: `token`, `deckId`, `timeframeDays`.
37+
- Output: `FetchMissedCardsResult` with an array of `Card`s.
38+
- Logic: Fetches all card IDs for the deck, then queries `review_events` for "MISSED" events associated with those card IDs within the timeframe.
39+
40+
## Review Event Logging
41+
42+
- **Creating Review Event**: `createReviewEventAction` records the result of a card review.
43+
- Input: `cardId`, `deckId`, `result` (enum `ReviewResult`).
44+
- Output: `CreateReviewEventResult` with the ID of the new review event.
45+
46+
## Data Structures (`[app/types.ts](mdc:app/types.ts)`)
47+
48+
- **`Card`**: Client-facing card structure with `id: string`.
49+
```typescript
50+
export interface Card {
51+
id: string;
52+
deck_id: string;
53+
front_text: string;
54+
back_text: string;
55+
createdAt?: Date;
56+
updatedAt?: Date;
57+
}
58+
```
59+
- **`CardDocument`**: MongoDB structure for cards with `_id: ObjectId` and `deck_id: ObjectId`.
60+
- **`ReviewResult`**: Enum for review outcomes (`EASY`, `MEDIUM`, `HARD`, `MISSED`).
61+
```typescript
62+
export enum ReviewResult {
63+
EASY = "easy",
64+
MEDIUM = "medium",
65+
HARD = "hard",
66+
MISSED = "missed",
67+
}
68+
```
69+
- **`ReviewEvent`**: Client-facing review event structure with `id: string`.
70+
```typescript
71+
export interface ReviewEvent {
72+
id: string;
73+
card_id: string;
74+
result: ReviewResult;
75+
timestamp: Date;
76+
}
77+
```
78+
- **`ReviewEventDocument`**: MongoDB structure for review events with `_id: ObjectId` and `card_id: ObjectId`.
79+
80+
## Helper Functions
81+
82+
- `mapCardDocument` (in `[app/actions/cards.ts](mdc:app/actions/cards.ts)`): Converts `CardDocument` (from MongoDB) to `Card` (client-facing), mapping `_id` to `id` and `deck_id` to a string.

app/deck/[deckId]/overview/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,10 @@ export default function DeckOverviewPage() {
331331
<h2 className="text-xl font-semibold text-gray-800">Cards in Deck ({cards ? cards.length : 0})</h2>
332332
</div>
333333

334-
{cardsLoading && (typeof cards === 'undefined' || cards.length === 0) && (
334+
{cardsLoading && (typeof cards === 'undefined') && (
335335
<div className="text-center text-gray-500 py-4">Loading cards...</div>
336336
)}
337-
{!cardsLoading && (typeof cards === 'undefined' || cards.length === 0) && (
337+
{!cardsLoading && (typeof cards === 'undefined') && (
338338
<div className="text-center text-gray-500 py-4">No cards in this deck.</div>
339339
)}
340340

app/deck/[deckId]/play/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function PlayDeckPage() {
4949
const missedCardsQuery = useMissedCardsForDeckInTimeframe({
5050
deckId,
5151
timeframeDays: timeframeDaysParsed,
52-
token,
52+
token: token ?? undefined,
5353
enabled: playStrategy === 'missedInTimeframe' && !!deckId && !!timeframeDaysParsed && timeframeDaysParsed > 0 && !!token,
5454
});
5555

0 commit comments

Comments
 (0)