stynx_code_tools/infrastructure/
todo_store.rs1use std::sync::{Mutex, OnceLock};
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct TodoItem {
7 pub id: String,
8 pub content: String,
9 pub status: String,
10 pub priority: String,
11 #[serde(default, rename = "activeForm")]
12 pub active_form: Option<String>,
13}
14
15static TODOS: OnceLock<Mutex<Vec<TodoItem>>> = OnceLock::new();
16
17fn store() -> &'static Mutex<Vec<TodoItem>> {
18 TODOS.get_or_init(|| Mutex::new(Vec::new()))
19}
20
21pub fn read_todos() -> Vec<TodoItem> {
22 store().lock().unwrap().clone()
23}
24
25pub fn write_todos(todos: Vec<TodoItem>) {
26 *store().lock().unwrap() = todos;
27}
28
29pub fn current_active_form() -> Option<String> {
30 store()
31 .lock()
32 .unwrap()
33 .iter()
34 .find(|t| t.status == "in_progress")
35 .and_then(|t| t.active_form.clone())
36}