actions.ts — react Source File
Architecture documentation for actions.ts, a typescript file in the react codebase. 1 imports, 4 dependents.
Entity Profile
Dependency Diagram
graph LR a2e3768b_191e_9986_afcb_87f97e20160d["actions.ts"] c0588312_ab09_8f72_8d9e_95868024d651["promises"] a2e3768b_191e_9986_afcb_87f97e20160d --> c0588312_ab09_8f72_8d9e_95868024d651 e8761808_43d6_8512_b503_192a97c4359a["TodoCreate.tsx"] e8761808_43d6_8512_b503_192a97c4359a --> a2e3768b_191e_9986_afcb_87f97e20160d 9d193cb4_26df_d78d_77c8_1c784c234257["TodoDetail.tsx"] 9d193cb4_26df_d78d_77c8_1c784c234257 --> a2e3768b_191e_9986_afcb_87f97e20160d ecd0fab8_8cce_e1b2_b31c_d05de8663169["TodoItem.tsx"] ecd0fab8_8cce_e1b2_b31c_d05de8663169 --> a2e3768b_191e_9986_afcb_87f97e20160d c0c08439_2d95_7b70_f20b_1bbbbdc9a402["TodoList.tsx"] c0c08439_2d95_7b70_f20b_1bbbbdc9a402 --> a2e3768b_191e_9986_afcb_87f97e20160d style a2e3768b_191e_9986_afcb_87f97e20160d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
'use server';
import fs from 'fs/promises';
export interface Todo {
id: number;
title: string;
description: string;
dueDate: string;
isComplete: boolean;
}
export async function getTodos(): Promise<Todo[]> {
try {
let contents = await fs.readFile('todos.json', 'utf8');
return JSON.parse(contents);
} catch {
await fs.writeFile('todos.json', '[]');
return [];
}
}
export async function getTodo(id: number): Promise<Todo | undefined> {
let todos = await getTodos();
return todos.find(todo => todo.id === id);
}
export async function createTodo(formData: FormData) {
let todos = await getTodos();
let title = formData.get('title');
let description = formData.get('description');
let dueDate = formData.get('dueDate');
let id = todos.length > 0 ? Math.max(...todos.map(todo => todo.id)) + 1 : 0;
todos.push({
id,
title: typeof title === 'string' ? title : '',
description: typeof description === 'string' ? description : '',
dueDate: typeof dueDate === 'string' ? dueDate : new Date().toISOString(),
isComplete: false,
});
await fs.writeFile('todos.json', JSON.stringify(todos));
}
export async function updateTodo(id: number, formData: FormData) {
let todos = await getTodos();
let title = formData.get('title');
let description = formData.get('description');
let dueDate = formData.get('dueDate');
let todo = todos.find(todo => todo.id === id);
if (todo) {
todo.title = typeof title === 'string' ? title : '';
todo.description = typeof description === 'string' ? description : '';
todo.dueDate =
typeof dueDate === 'string' ? dueDate : new Date().toISOString();
await fs.writeFile('todos.json', JSON.stringify(todos));
}
}
export async function setTodoComplete(id: number, isComplete: boolean) {
let todos = await getTodos();
let todo = todos.find(todo => todo.id === id);
if (todo) {
todo.isComplete = isComplete;
await fs.writeFile('todos.json', JSON.stringify(todos));
}
}
export async function deleteTodo(id: number) {
let todos = await getTodos();
let index = todos.findIndex(todo => todo.id === id);
if (index >= 0) {
todos.splice(index, 1);
await fs.writeFile('todos.json', JSON.stringify(todos));
}
}
Domain
Subdomains
Types
Dependencies
- promises
Imported By
Source
Frequently Asked Questions
What does actions.ts do?
actions.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Optimization subdomain.
What functions are defined in actions.ts?
actions.ts defines 6 function(s): createTodo, deleteTodo, getTodo, getTodos, setTodoComplete, updateTodo.
What does actions.ts depend on?
actions.ts imports 1 module(s): promises.
What files import actions.ts?
actions.ts is imported by 4 file(s): TodoCreate.tsx, TodoDetail.tsx, TodoItem.tsx, TodoList.tsx.
Where is actions.ts in the architecture?
actions.ts is located at fixtures/flight-parcel/src/actions.ts (domain: BabelCompiler, subdomain: Optimization, directory: fixtures/flight-parcel/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free