-
-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add typing indicator for better UI experience issue #8 #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Shreenath-14
wants to merge
7
commits into
ZenYukti:main
Choose a base branch
from
Shreenath-14:feat-typing-indicator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f47028f
feat: add environment variable validation for backend
Shreenath-14 b4b4a8d
feat: add typing indicator for better UI experience
Shreenath-14 b43ac7c
Update backend/src/config/env.ts
ayushHardeniya cd1cd9a
refactor: address PR feedback and fix type safety issues
Shreenath-14 c2483dd
Merge branch 'main' into feat-typing-indicator
Shreenath-14 87cb3d7
refactor: manual cleanup and specific PR fixes
Shreenath-14 aa771c1
Update frontend/src/components/ChatRoom.tsx
Blazzzeee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,15 @@ | ||
| # Backend Environment Variables | ||
| # Copy this to .env and fill in your actual values | ||
|
|
||
| # Supabase Configuration (get from https://app.supabase.com → Project Settings → API) | ||
| # Supabase Configuration | ||
| SUPABASE_URL=https://your-project-id.supabase.co | ||
| SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... | ||
| SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... | ||
| SUPABASE_ANON_KEY=your-anon-key | ||
| SUPABASE_SERVICE_ROLE_KEY=your-service-role-key | ||
|
|
||
| # HuggingFace API Token (optional - get from https://huggingface.co/settings/tokens) | ||
| # If not provided, crisis detection will use keyword-based fallback | ||
| # HuggingFace API Token (Optional) | ||
| HUGGINGFACE_API_TOKEN=hf_YourTokenHere | ||
|
|
||
| # Frontend URL (for CORS whitelist) | ||
| FRONTEND_URL=http://localhost:3000 | ||
|
|
||
| # Server Configuration | ||
| PORT=3001 | ||
| FRONTEND_URL=http://localhost:3000 | ||
|
|
||
| # Rate Limiting (optional - defaults shown) | ||
| # Rate Limiting | ||
| RATE_LIMIT_WINDOW_MS=900000 | ||
| RATE_LIMIT_MAX_REQUESTS=100 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { z } from 'zod'; | ||
| import dotenv from 'dotenv'; | ||
|
|
||
| dotenv.config(); | ||
|
|
||
| const envSchema = z.object({ | ||
| // Supabase Configuration | ||
| SUPABASE_URL: z.string().url(), | ||
| SUPABASE_ANON_KEY: z.string().min(1), | ||
| SUPABASE_SERVICE_ROLE_KEY: z.string().min(1), | ||
|
|
||
| // HuggingFace API Token (Optional) | ||
| HUGGINGFACE_API_TOKEN: z.string().optional(), | ||
|
|
||
| // Server Configuration | ||
| FRONTEND_URL: z.string().url().default('http://localhost:3000'), | ||
| PORT: z.coerce.number().default(3001), | ||
|
|
||
| // Rate Limiting | ||
| RATE_LIMIT_WINDOW_MS: z.coerce.number().default(900000), | ||
| RATE_LIMIT_MAX_REQUESTS: z.coerce.number().default(100), | ||
| }); | ||
|
|
||
| const _env = envSchema.safeParse(process.env); | ||
|
|
||
| if (!_env.success) { | ||
| console.error('Invalid environment variables:'); | ||
| console.error(JSON.stringify(_env.error.format(), null, 4)); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| export const env = _env.data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,22 @@ | ||
| import dotenv from 'dotenv'; | ||
| import { env } from './env'; | ||
|
|
||
| dotenv.config(); | ||
|
|
||
| interface Config { | ||
| const config = { | ||
| supabase: { | ||
| url: string; | ||
| anonKey: string; | ||
| serviceRoleKey: string; | ||
| }; | ||
| huggingface: { | ||
| apiToken?: string; | ||
| }; | ||
| server: { | ||
| port: number; | ||
| frontendUrl: string; | ||
| }; | ||
| rateLimit: { | ||
| windowMs: number; | ||
| maxRequests: number; | ||
| }; | ||
| } | ||
|
|
||
| const config: Config = { | ||
| supabase: { | ||
| url: process.env.SUPABASE_URL || '', | ||
| anonKey: process.env.SUPABASE_ANON_KEY || '', | ||
| serviceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY || '', | ||
| url: env.SUPABASE_URL, | ||
| anonKey: env.SUPABASE_ANON_KEY, | ||
| serviceRoleKey: env.SUPABASE_SERVICE_ROLE_KEY, | ||
| }, | ||
| huggingface: { | ||
| apiToken: process.env.HUGGINGFACE_API_TOKEN, | ||
| apiToken: env.HUGGINGFACE_API_TOKEN, | ||
| }, | ||
| server: { | ||
| port: parseInt(process.env.PORT || '3001', 10), | ||
| frontendUrl: process.env.FRONTEND_URL || 'http://localhost:3000', | ||
| port: env.PORT, | ||
| frontendUrl: env.FRONTEND_URL, | ||
| }, | ||
| rateLimit: { | ||
| windowMs: parseInt(process.env.RATE_LIMIT_WINDOW_MS || '900000', 10), | ||
| maxRequests: parseInt(process.env.RATE_LIMIT_MAX_REQUESTS || '100', 10), | ||
| windowMs: env.RATE_LIMIT_WINDOW_MS, | ||
| maxRequests: env.RATE_LIMIT_MAX_REQUESTS, | ||
| }, | ||
| }; | ||
|
|
||
| // Validation | ||
| const requiredEnvVars = [ | ||
| 'SUPABASE_URL', | ||
| 'SUPABASE_ANON_KEY', | ||
| 'SUPABASE_SERVICE_ROLE_KEY', | ||
| 'FRONTEND_URL', | ||
| ]; | ||
|
|
||
| const missingVars = requiredEnvVars.filter((varName) => !process.env[varName]); | ||
|
|
||
| if (missingVars.length > 0) { | ||
| throw new Error( | ||
| `Missing required environment variables: ${missingVars.join(', ')}\n` + | ||
| 'Please check your .env file and ensure all required variables are set.' | ||
| ); | ||
| } | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handleTypingtrustsws.roomId/userIdmetadata without verifying the socket is still a member of that room. BecausehandleLeaveremoves the member from the room set but doesn’t clearws.roomId/userId, a client that sendsleave(but keeps the connection open) can still broadcast typing events to the room. Consider either clearingws.roomId/ws.userId/ws.nicknameon leave, and/or checking membership inthis.rooms.get(roomId)before broadcasting.