wip frontend

This commit is contained in:
2023-06-11 07:47:01 +02:00
parent 6e845907d1
commit bfabcc0abc
15 changed files with 771 additions and 18 deletions

View File

@@ -29,7 +29,7 @@ const APP_STATE_FILE: &str = "achievements.json";
type SharedState = Arc<tokio::sync::RwLock<SharedStateParts>>;
struct SharedStateParts {
app_state: AppState,
watcher_tx: tokio::sync::watch::Sender<AppState>,
watcher_tx: tokio::sync::watch::Sender<common::State>,
}
#[tokio::main]
@@ -47,7 +47,7 @@ async fn main() {
}
Err(e) => panic!("Unexpected error: {:?}", e),
};
let (app_state_watch_tx, app_state_watch_rx) = tokio::sync::watch::channel(init_app_state.clone());
let (app_state_watch_tx, app_state_watch_rx) = tokio::sync::watch::channel(init_app_state.state.clone());
let app_state: SharedState = Arc::new(tokio::sync::RwLock::new(SharedStateParts {
app_state: init_app_state,
watcher_tx: app_state_watch_tx,
@@ -166,9 +166,9 @@ async fn create_achievement(
uuid: uuid::Uuid::new_v4(),
};
let mut lock = app_state.write().await;
lock.app_state.achievements.push(achievement);
lock.app_state.state.achievements.push(achievement);
lock.watcher_tx
.send(lock.app_state.clone())
.send(lock.app_state.state.clone())
.expect("watch channel is closed, every receiver was dropped.");
Ok((StatusCode::CREATED, ()))
}
@@ -180,13 +180,14 @@ async fn delete_achievement(
let mut lock = app_state.write().await;
if let Some(pos) = lock
.app_state
.state
.achievements
.iter()
.position(|x| x.uuid == delete_achievement.uuid)
{
lock.app_state.achievements.remove(pos);
lock.app_state.state.achievements.remove(pos);
lock.watcher_tx
.send(lock.app_state.clone())
.send(lock.app_state.state.clone())
.expect("watch channel is closed, every receiver was dropped.");
}
Ok((StatusCode::OK, ()))
@@ -220,7 +221,7 @@ async fn shutdown_signal() {
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
struct AppState {
achievements: Vec<Achievement>,
state: common::State,
}
impl AppState {