From ca0188c87b7043ef0a05977b6e77e9d293c838f8 Mon Sep 17 00:00:00 2001 From: isark Date: Wed, 16 Aug 2023 21:58:56 +0200 Subject: [PATCH] added support to load previous plans, still missing scrollbar functionality in the list so having too many makes them get hidden --- src-tauri/src/main.rs | 34 ++++++++++++------- src-tauri/src/storage.rs | 11 +++++- .../plan-display/plan-display.component.html | 6 ++++ .../plan-display/plan-display.component.scss | 14 ++++++++ .../plan-display/plan-display.component.ts | 6 ++++ src/app/plan-display/plan-display.module.ts | 9 ++--- src/app/services/plan.service.ts | 4 +++ 7 files changed, 67 insertions(+), 17 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index b878932..57fe91e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -95,6 +95,16 @@ fn load_stored_plans() -> Vec { Storage::enumerate_plans() } +#[tauri::command] +fn load_previous(name: String, state: tauri::State>) -> Option { + if let Ok(mut storage) = state.lock() { + let plan = Storage::load_by_name(name); + log::info!("got plan: {plan:?}"); + return plan; + } + None +} + #[tauri::command] fn base_plan() -> Plan { const BASE_PLAN_STRING: &str = include_str!("../../data/base_plan.json"); @@ -150,7 +160,8 @@ fn main() { load_plan, load_stored_plans, save_plan, - base_plan + base_plan, + load_previous ]) .system_tray(system_tray) .on_system_tray_event(|app, event| match event { @@ -180,20 +191,19 @@ fn main() { } fn listen_for_zone_changes(poe_client_log_path: Option, window: Window) { - std::thread::spawn(move || { - // need _watcher - if let Some((enter_area_receiver, _watcher)) = receiver_from_path(&poe_client_log_path) { - let world_areas: WorldAreasMap = load_world_areas(); - for area in blocking_area_filtered_rx(&enter_area_receiver) { - - if let Some(area) = filter_func(area) { - if let Some(entered) = world_areas.get(&area) { - window.emit_to("Overlay", "entered", &entered.named_id).ok(); - } + std::thread::spawn(move || { + // need _watcher + if let Some((enter_area_receiver, _watcher)) = receiver_from_path(&poe_client_log_path) { + let world_areas: WorldAreasMap = load_world_areas(); + for area in blocking_area_filtered_rx(&enter_area_receiver) { + if let Some(area) = filter_func(area) { + if let Some(entered) = world_areas.get(&area) { + window.emit_to("Overlay", "entered", &entered.named_id).ok(); } } } - }); + } + }); } fn receiver_from_path(path: &Option) -> Option<(Receiver, PollWatcher)> { diff --git a/src-tauri/src/storage.rs b/src-tauri/src/storage.rs index ae8387f..ea4abb1 100644 --- a/src-tauri/src/storage.rs +++ b/src-tauri/src/storage.rs @@ -117,11 +117,20 @@ impl Storage { } } + pub fn load_by_name>(file: T) -> Option { + let file = file.into(); + let file = proj_dir()?.data_dir().join(SAVED_PLANS).join(file); + + log::info!("Loading plan: {file:?}"); + + serde_json::from_str(&std::fs::read_to_string(&file).ok()?).ok() + } + pub fn enumerate_plans() -> Vec { if let Some(proj_dir) = proj_dir() { if let Ok(read_dir) = proj_dir.data_dir().join(SAVED_PLANS).read_dir() { return read_dir - .filter_map(|entry| Some(entry.ok()?.path().to_str()?.to_string())) + .filter_map(|entry| Some(entry.ok()?.path().file_name()?.to_str()?.to_string())) .collect::>(); } } diff --git a/src/app/plan-display/plan-display.component.html b/src/app/plan-display/plan-display.component.html index 1e81d43..5a557b5 100644 --- a/src/app/plan-display/plan-display.component.html +++ b/src/app/plan-display/plan-display.component.html @@ -37,6 +37,12 @@ +
+ + + + +
diff --git a/src/app/plan-display/plan-display.component.scss b/src/app/plan-display/plan-display.component.scss index 86a44d2..9014692 100644 --- a/src/app/plan-display/plan-display.component.scss +++ b/src/app/plan-display/plan-display.component.scss @@ -124,4 +124,18 @@ notes { 'wght' 400, 'GRAD' 0, 'opsz' 48 +} + +.planChooser { + overflow: hidden; +} + +.enumerated { + display: block; + overflow: hidden; + + mat-list { + max-height: 100%; + overflow-y: scroll; + } } \ No newline at end of file diff --git a/src/app/plan-display/plan-display.component.ts b/src/app/plan-display/plan-display.component.ts index 30ce77c..9fd3a1f 100644 --- a/src/app/plan-display/plan-display.component.ts +++ b/src/app/plan-display/plan-display.component.ts @@ -70,6 +70,8 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { } } }); + + this.planService.getPreviousPlans(); } windowInitHandler() { @@ -234,4 +236,8 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { this.planService.currentPlan = plan; }) } + + enumeratedPlans() { + + } } diff --git a/src/app/plan-display/plan-display.module.ts b/src/app/plan-display/plan-display.module.ts index 7d63013..0eac398 100644 --- a/src/app/plan-display/plan-display.module.ts +++ b/src/app/plan-display/plan-display.module.ts @@ -8,9 +8,9 @@ import { NotesComponent } from '../editor/notes/notes.component'; import { AngularResizeEventModule } from 'angular-resize-event'; import { SettingsComponent } from '../settings/settings.component'; import { OverlayModule } from '@angular/cdk/overlay'; -import {MatIconModule} from '@angular/material/icon'; -import { MatButtonModule } from '@angular/material/button'; - +import { MatIconModule } from '@angular/material/icon'; +import { MatButtonModule } from '@angular/material/button'; +import { MatListModule } from '@angular/material/list'; @NgModule({ declarations: [ PlanDisplayComponent @@ -26,7 +26,8 @@ import { MatButtonModule } from '@angular/material/button'; OverlayModule, MatIconModule, MatButtonModule, - MatIconModule + MatIconModule, + MatListModule ], exports: [ PlanDisplayComponent diff --git a/src/app/services/plan.service.ts b/src/app/services/plan.service.ts index cc43436..2b47474 100644 --- a/src/app/services/plan.service.ts +++ b/src/app/services/plan.service.ts @@ -44,4 +44,8 @@ export class PlanService { getPreviousPlans() { from(invoke('load_stored_plans')).subscribe(plans => this.planStore = plans); } + + loadPrevious(name: string) { + from(invoke('load_previous', {name})).subscribe(plan => this.currentPlan = plan); + } }