From a435e3ce5dc79a614bc7a42f699b7973a367c782 Mon Sep 17 00:00:00 2001 From: Louis Knight-Webb Date: Sun, 15 Jun 2025 14:39:45 -0400 Subject: [PATCH] Cleanup types --- AGENT.md | 2 +- backend/src/bin/generate_types.rs | 28 +++---- frontend/src/components/auth/login-form.tsx | 2 +- .../components/projects/project-detail.tsx | 2 +- .../src/components/projects/project-form.tsx | 2 +- .../src/components/projects/project-list.tsx | 2 +- frontend/src/components/users/user-form.tsx | 2 +- frontend/src/components/users/user-list.tsx | 2 +- frontend/src/contexts/auth-context.tsx | 6 +- frontend/src/lib/auth.ts | 2 +- frontend/src/pages/home.tsx | 2 +- frontend/src/pages/project-tasks.tsx | 2 +- frontend/src/pages/users.tsx | 2 +- frontend/src/types/index.ts | 76 ------------------- shared/types.ts | 26 +++---- 15 files changed, 42 insertions(+), 116 deletions(-) delete mode 100644 frontend/src/types/index.ts diff --git a/AGENT.md b/AGENT.md index 36e8d36d..71bf66be 100644 --- a/AGENT.md +++ b/AGENT.md @@ -59,7 +59,7 @@ bloop/ ts-rs allows you to derive TypeScript types from Rust structs/enums. By annotating your Rust types with #[derive(TS)] and related macros, ts-rs will generate .ts declaration files for those types. When making changes to the types, you can regenerate them using `npm run generate-types` -Do not manually edit shared/types.ts +Do not manually edit shared/types.ts, instead edit backend/src/bin/generate_types.rs # Working on the frontend AND the backend diff --git a/backend/src/bin/generate_types.rs b/backend/src/bin/generate_types.rs index 446bba72..8a2b5e4d 100644 --- a/backend/src/bin/generate_types.rs +++ b/backend/src/bin/generate_types.rs @@ -31,39 +31,39 @@ fn main() { r#"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // Auto-generated from Rust backend types using ts-rs -{} +export {} -{} +export {} -{} +export {} -{} +export {} -{} +export {} -{} +export {} -{} +export {} -{} +export {} -{} +export {} -{} +export {} -{} +export {} -{} +export {} -{} +export {} "#, bloop_backend::models::ApiResponse::<()>::decl(), bloop_backend::models::project::CreateProject::decl(), bloop_backend::models::project::Project::decl(), bloop_backend::models::project::UpdateProject::decl(), bloop_backend::models::task::CreateTask::decl(), - bloop_backend::models::task::Task::decl(), bloop_backend::models::task::TaskStatus::decl(), + bloop_backend::models::task::Task::decl(), bloop_backend::models::task::UpdateTask::decl(), bloop_backend::models::user::CreateUser::decl(), bloop_backend::models::user::LoginRequest::decl(), diff --git a/frontend/src/components/auth/login-form.tsx b/frontend/src/components/auth/login-form.tsx index c0990315..a320397f 100644 --- a/frontend/src/components/auth/login-form.tsx +++ b/frontend/src/components/auth/login-form.tsx @@ -4,7 +4,7 @@ import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Alert, AlertDescription } from '@/components/ui/alert' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' -import { LoginRequest, LoginResponse, ApiResponse } from '@/types' +import { LoginRequest, LoginResponse, ApiResponse } from 'shared/types' import { useAuth } from '@/contexts/auth-context' import { LogIn, AlertCircle } from 'lucide-react' diff --git a/frontend/src/components/projects/project-detail.tsx b/frontend/src/components/projects/project-detail.tsx index d05dfa65..cc343ba6 100644 --- a/frontend/src/components/projects/project-detail.tsx +++ b/frontend/src/components/projects/project-detail.tsx @@ -4,7 +4,7 @@ import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Alert, AlertDescription } from '@/components/ui/alert' -import { Project, ApiResponse } from '@/types' +import { Project, ApiResponse } from 'shared/types' import { ProjectForm } from './project-form' import { makeAuthenticatedRequest } from '@/lib/auth' import { ArrowLeft, Edit, Trash2, Calendar, Clock, User, AlertCircle, Loader2, CheckSquare } from 'lucide-react' diff --git a/frontend/src/components/projects/project-form.tsx b/frontend/src/components/projects/project-form.tsx index d38d5b08..091a9870 100644 --- a/frontend/src/components/projects/project-form.tsx +++ b/frontend/src/components/projects/project-form.tsx @@ -4,7 +4,7 @@ import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Alert, AlertDescription } from '@/components/ui/alert' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog' -import { Project, CreateProject, UpdateProject } from '@/types' +import { Project, CreateProject, UpdateProject } from 'shared/types' import { AlertCircle } from 'lucide-react' import { makeAuthenticatedRequest } from '@/lib/auth' diff --git a/frontend/src/components/projects/project-list.tsx b/frontend/src/components/projects/project-list.tsx index 7e3e82bd..032d2406 100644 --- a/frontend/src/components/projects/project-list.tsx +++ b/frontend/src/components/projects/project-list.tsx @@ -4,7 +4,7 @@ import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Alert, AlertDescription } from '@/components/ui/alert' -import { Project, ApiResponse } from '@/types' +import { Project, ApiResponse } from 'shared/types' import { ProjectForm } from './project-form' import { makeAuthenticatedRequest } from '@/lib/auth' import { Plus, Edit, Trash2, Calendar, AlertCircle, Loader2, CheckSquare } from 'lucide-react' diff --git a/frontend/src/components/users/user-form.tsx b/frontend/src/components/users/user-form.tsx index 0834f347..ff4dfa9f 100644 --- a/frontend/src/components/users/user-form.tsx +++ b/frontend/src/components/users/user-form.tsx @@ -4,7 +4,7 @@ import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Alert, AlertDescription } from '@/components/ui/alert' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog' -import { User, CreateUser, UpdateUser } from '@/types' +import { User, CreateUser, UpdateUser } from 'shared/types' import { makeAuthenticatedRequest, authStorage } from '@/lib/auth' import { AlertCircle } from 'lucide-react' diff --git a/frontend/src/components/users/user-list.tsx b/frontend/src/components/users/user-list.tsx index b573ce2c..4a239464 100644 --- a/frontend/src/components/users/user-list.tsx +++ b/frontend/src/components/users/user-list.tsx @@ -3,7 +3,7 @@ import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Alert, AlertDescription } from '@/components/ui/alert' -import { User, ApiResponse } from '@/types' +import { User, ApiResponse } from 'shared/types' import { UserForm } from './user-form' import { makeAuthenticatedRequest, authStorage } from '@/lib/auth' import { Plus, Edit, Trash2, Calendar, AlertCircle, Loader2, Shield, User as UserIcon } from 'lucide-react' diff --git a/frontend/src/contexts/auth-context.tsx b/frontend/src/contexts/auth-context.tsx index 7244034f..5cd71c3e 100644 --- a/frontend/src/contexts/auth-context.tsx +++ b/frontend/src/contexts/auth-context.tsx @@ -1,6 +1,6 @@ import { createContext, useContext, useState, useEffect, ReactNode } from 'react' import { isAuthenticated, authStorage, makeAuthenticatedRequest } from '@/lib/auth' -import { User } from '@/types' +import { User } from 'shared/types' interface AuthContextType { user: User | null @@ -39,7 +39,9 @@ export function AuthProvider({ children }: AuthProviderProps) { const userData: User = { id: data.data.user_id, email: data.data.email, - is_admin: data.data.is_admin || false + is_admin: data.data.is_admin || false, + created_at: new Date(), + updated_at: new Date() } authStorage.setUser(userData) setUser(userData) diff --git a/frontend/src/lib/auth.ts b/frontend/src/lib/auth.ts index e7a6ef6c..5d5b1f6f 100644 --- a/frontend/src/lib/auth.ts +++ b/frontend/src/lib/auth.ts @@ -1,4 +1,4 @@ -import { User } from '@/types' +import { User } from 'shared/types' const TOKEN_KEY = 'auth_token' const USER_KEY = 'auth_user' diff --git a/frontend/src/pages/home.tsx b/frontend/src/pages/home.tsx index d1c1d272..3cdc5f15 100644 --- a/frontend/src/pages/home.tsx +++ b/frontend/src/pages/home.tsx @@ -10,7 +10,7 @@ import { } from "@/components/ui/card"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; -import { ApiResponse } from "@/types"; +import { ApiResponse } from "shared/types"; import { authStorage, makeAuthenticatedRequest } from "@/lib/auth"; import { Heart, diff --git a/frontend/src/pages/project-tasks.tsx b/frontend/src/pages/project-tasks.tsx index bcfece24..295c644e 100644 --- a/frontend/src/pages/project-tasks.tsx +++ b/frontend/src/pages/project-tasks.tsx @@ -34,7 +34,7 @@ import { KanbanCard, type DragEndEvent } from '@/components/ui/shadcn-io/kanban' -import type { TaskStatus } from '@/types' +import type { TaskStatus } from 'shared/types' interface Task { id: string diff --git a/frontend/src/pages/users.tsx b/frontend/src/pages/users.tsx index 4ab77b60..7b9d63c3 100644 --- a/frontend/src/pages/users.tsx +++ b/frontend/src/pages/users.tsx @@ -3,7 +3,7 @@ import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Alert, AlertDescription } from '@/components/ui/alert' -import { User, ApiResponse } from '@/types' +import { User, ApiResponse } from 'shared/types' import { UserForm } from '@/components/users/user-form' import { makeAuthenticatedRequest, authStorage } from '@/lib/auth' import { Plus, Edit, Trash2, Calendar, AlertCircle, Loader2, Shield, User as UserIcon } from 'lucide-react' diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts deleted file mode 100644 index 8dcae3db..00000000 --- a/frontend/src/types/index.ts +++ /dev/null @@ -1,76 +0,0 @@ -// Shared types for the frontend application -export interface User { - id: string - email: string - is_admin: boolean - created_at?: Date - updated_at?: Date -} - -export interface ApiResponse { - success: boolean - data: T | null - message: string | null -} - -export interface LoginRequest { - email: string - password: string -} - -export interface LoginResponse { - user: User - token: string -} - -export interface Project { - id: string - name: string - owner_id: string - created_at: Date - updated_at: Date -} - -export interface CreateProject { - name: string -} - -export interface UpdateProject { - name: string | null -} - -export interface Task { - id: string - project_id: string - title: string - description: string | null - status: TaskStatus - created_at: string - updated_at: string -} - -export type TaskStatus = "todo" | "inprogress" | "inreview" | "done" | "cancelled" - -export interface CreateTask { - project_id: string - title: string - description: string | null -} - -export interface UpdateTask { - title: string | null - description: string | null - status: TaskStatus | null -} - -export interface CreateUser { - email: string - password: string - is_admin: boolean | null -} - -export interface UpdateUser { - email: string | null - password: string | null - is_admin: boolean | null -} diff --git a/shared/types.ts b/shared/types.ts index 3a83185d..1c8a9f59 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -1,28 +1,28 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // Auto-generated from Rust backend types using ts-rs -type ApiResponse = { success: boolean, data: T | null, message: string | null, }; +export type ApiResponse = { success: boolean, data: T | null, message: string | null, }; -type CreateProject = { name: string, }; +export type CreateProject = { name: string, }; -type Project = { id: string, name: string, owner_id: string, created_at: Date, updated_at: Date, }; +export type Project = { id: string, name: string, owner_id: string, created_at: Date, updated_at: Date, }; -type UpdateProject = { name: string | null, }; +export type UpdateProject = { name: string | null, }; -type CreateTask = { project_id: string, title: string, description: string | null, }; +export type CreateTask = { project_id: string, title: string, description: string | null, }; -type Task = { id: string, project_id: string, title: string, description: string | null, status: TaskStatus, created_at: string, updated_at: string, }; +export type TaskStatus = "todo" | "inprogress" | "inreview" | "done" | "cancelled"; -type TaskStatus = "todo" | "inprogress" | "inreview" | "done" | "cancelled"; +export type Task = { id: string, project_id: string, title: string, description: string | null, status: TaskStatus, created_at: string, updated_at: string, }; -type UpdateTask = { title: string | null, description: string | null, status: TaskStatus | null, }; +export type UpdateTask = { title: string | null, description: string | null, status: TaskStatus | null, }; -type CreateUser = { email: string, password: string, is_admin: boolean | null, }; +export type CreateUser = { email: string, password: string, is_admin: boolean | null, }; -type LoginRequest = { email: string, password: string, }; +export type LoginRequest = { email: string, password: string, }; -type LoginResponse = { user: User, token: string, }; +export type LoginResponse = { user: User, token: string, }; -type UpdateUser = { email: string | null, password: string | null, is_admin: boolean | null, }; +export type UpdateUser = { email: string | null, password: string | null, is_admin: boolean | null, }; -type User = { id: string, email: string, is_admin: boolean, created_at: Date, updated_at: Date, }; +export type User = { id: string, email: string, is_admin: boolean, created_at: Date, updated_at: Date, };