File size: 6,787 Bytes
5c36ac3
 
 
 
 
 
 
 
 
d4b0c6b
c15fa2f
7c8619c
c15fa2f
7c8619c
c15fa2f
6043a6a
7c8619c
 
 
 
 
 
 
 
6043a6a
7c8619c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6043a6a
7c8619c
c21ae5c
7c8619c
 
 
 
 
 
 
 
6043a6a
7c8619c
 
c21ae5c
 
 
 
 
 
 
 
7c8619c
 
c21ae5c
 
7c8619c
c21ae5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c8619c
 
c21ae5c
 
 
 
 
 
7c8619c
 
 
 
c15fa2f
7c8619c
c15fa2f
 
7c8619c
 
6043a6a
7c8619c
 
 
 
6043a6a
7c8619c
6043a6a
7c8619c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c21ae5c
 
 
7c8619c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c21ae5c
6043a6a
c21ae5c
 
 
7c8619c
 
 
c21ae5c
 
 
7c8619c
c21ae5c
 
7c8619c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c15fa2f
7c8619c
 
 
 
c15fa2f
7c8619c
c15fa2f
7c8619c
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
---
title: Brainstorm Ui
emoji: 🌍
colorFrom: pink
colorTo: yellow
sdk: docker
pinned: false
---

# English Test Brainstorming App

A modern web application for browsing and practicing CELPIP-style speaking and writing tasks with brainstorming prompts, curated vocabulary, and sample responses. Features mandatory user authentication, task tracking, and progress management with Supabase integration.

## Features

- **Authentication**: Users must log in to access any content
- **Task Tracking**: Mark tasks as completed to avoid re-practicing
- **Supabase Integration**: Real database for user authentication and progress tracking
- **Responsive Design**: Works on desktop and mobile devices
- **Advanced Filtering**: Filter by category, task type, and completion status

## Prerequisites

- Node.js (v16 or higher)
- `npm` or `yarn`
- Supabase account and project

## Setup Instructions

### 1. Install Dependencies

```bash
npm install
```

### 2. Supabase Database Setup

#### Create Tables
Run these SQL queries in your Supabase SQL Editor:

```sql
-- Task completions table for tracking progress
CREATE TABLE completed_tasks (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
    task_id VARCHAR(50) NOT NULL,
    task_type VARCHAR(50) NOT NULL,
    category VARCHAR(20) NOT NULL,
    completed_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    UNIQUE(user_id, task_id, task_type)
);

-- Indexes for better performance
CREATE INDEX idx_completed_tasks_user_id ON completed_tasks(user_id);
```

#### Enable Supabase Auth
Go to your Supabase project dashboard:
1. **Authentication** -> **Settings** -> Enable email/password authentication
2. **Authentication** -> **Email Template** -> Configure confirmation email template
3. **Authentication** -> **Settings** -> Set your site URL for redirects

#### Set Up Row Level Security (RLS)
Enable RLS for proper security with Supabase Auth:

```sql
-- Enable RLS on `completed_tasks` table
ALTER TABLE completed_tasks ENABLE ROW LEVEL SECURITY;

-- Users can only see their own completions
CREATE POLICY "Users can view own completions" ON completed_tasks
    FOR SELECT USING (auth.uid() = user_id);

-- Users can only insert their own completions
CREATE POLICY "Users can insert own completions" ON completed_tasks
    FOR INSERT WITH CHECK (auth.uid() = user_id);

-- Users can only update their own completions
CREATE POLICY "Users can update own completions" ON completed_tasks
    FOR UPDATE USING (auth.uid() = user_id);

-- Users can only delete their own completions
CREATE POLICY "Users can delete own completions" ON completed_tasks
    FOR DELETE USING (auth.uid() = user_id);
```

#### Create Test Users
Use the Supabase Auth UI or API to create test users:
1. Go to **Authentication** -> **Users** in your Supabase dashboard
2. Click **Add user** and create test accounts
3. Or use the signup functionality in your app


### 3. Environment Configuration

1. Copy the example environment file:
   ```bash
   cp .env.example .env
   ```

2. Fill in your Supabase credentials:
   - Go to your Supabase project dashboard
   - Settings -> API
   - Copy the Project URL and anon/public key

### 4. Prepare Data Files

Place your data files in the `./data/` directory:
- `speaking.jsonl` - Speaking tasks data
- `writing.jsonl` - Writing tasks data

### 5. Run the Development Server

```bash
npm run dev
```

The application will be available at `http://localhost:4323`

## Environment Variables

Required environment variables (see `.env.example`):

```env
SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key
```

## Usage

### Authentication
- **Login**: Users must log in with email and password to access any content
- **Session**: Sessions are managed automatically by Supabase (persistent)
- **Logout**: Clears session and shows login screen

### Task Management
- **Browse**: Filter tasks by category, type, and completion status
- **Track**: Mark tasks as completed to track progress
- **Avoid Repetition**: Completed tasks can be filtered out

### Data Structure

#### Speaking Tasks (`speaking.jsonl`)
```json
{
  "id": "unique_id",
  "task_type": "giving_advice",
  "category": "Speaking",
  "rephrased_task": "Task description...",
  "brainstorm": [{"title": "Idea", "description": "Description"}],
  "vocabulary": ["word1", "word2"],
  "response": "Sample response..."
}
```

#### Writing Tasks (`writing.jsonl`)
```json
{
  "id": "unique_id",
  "task_type": "writing_email",
  "category": "Writing",
  "rephrased_task": "Task description...",
  "brainstorm": [{"title": "Idea", "description": "Description"}],
  "response": "Sample response..."
}
```

## Development

### Project Structure
```
astra/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/     # Astro components
β”‚   β”œβ”€β”€ layouts/       # Layout components
β”‚   β”œβ”€β”€ pages/         # Page components
β”‚   β”œβ”€β”€ styles/        # Global styles
β”‚   └── utils/         # Utility functions
β”œβ”€β”€ data/              # JSON data files
β”œβ”€β”€ public/            # Static assets
└── scripts/           # Build scripts
```

### Key Components
- `src/pages/index.astro` - Main application page
- `src/components/LoginForm.astro` - Authentication form
- `src/layouts/BaseLayout.astro` - Base layout component

### Authentication Flow
1. Page loads -> Check Supabase auth session
2. If no session -> Show login overlay, hide content
3. User submits form -> Authenticate with Supabase Auth
4. If successful -> Supabase manages session, show content
5. Session persists automatically (managed by Supabase)

## Security Notes

- **Important**: Now uses Supabase Auth for secure authentication
- Row Level Security (RLS) ensures users can only access their own data
- Supabase handles password hashing and session management securely
- Use HTTPS in production
- RLS policies prevent unauthorized access to user data
- No sensitive data exposed in frontend code

## Troubleshooting

### Common Issues

1. **Login form not working**
   - Check browser console for JavaScript errors
   - Verify Supabase credentials are correct
   - Ensure database tables exist

2. **Data not loading**
   - Check that JSONL files are in the correct format
   - Verify file paths in the data loading functions
   - Check browser network tab for 404 errors

3. **Authentication issues**
   - Verify Supabase URL and keys are correct
   - Check that users exist in the database
   - Ensure RLS policies are set up correctly

### Build for Production

```bash
npm run build
npm run preview
```

## Deployment

The app can be deployed to any static hosting service that supports environment variables:
- Hugging Face Spaces
- Vercel
- Netlify
- Cloudflare Pages