From 38ac316dab310a0cc38624c5d880092f610a1963 Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Tue, 29 Aug 2023 10:43:21 +0200 Subject: [PATCH] chore: drop dead code --- spog/ui/src/hooks/search.rs | 88 ------------------------------------- 1 file changed, 88 deletions(-) diff --git a/spog/ui/src/hooks/search.rs b/spog/ui/src/hooks/search.rs index 73a051414..00d3dd827 100644 --- a/spog/ui/src/hooks/search.rs +++ b/spog/ui/src/hooks/search.rs @@ -2,99 +2,11 @@ use crate::{ components::search::{DynamicSearchParameters, SearchMode}, utils::search::*, }; -use gloo_utils::format::JsValueSerdeExt; use patternfly_yew::prelude::*; use spog_model::config::Filters; -use std::fmt::Debug; -use std::ops::{Deref, DerefMut}; use std::rc::Rc; -use wasm_bindgen::JsValue; use yew::prelude::*; -pub const DEFAULT_PAGE_SIZE: usize = 10; - -#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)] -pub struct SearchViewState { - pub search: T, - pub pagination: PaginationControl, -} - -impl Deref for SearchViewState { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.search - } -} - -impl DerefMut for SearchViewState { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.search - } -} - -#[hook] -pub fn use_search_view_state( - props_query: Option, - total: Option, - f: F, -) -> (UseStateHandle, UsePagination) -where - T: for<'de> serde::Deserialize<'de> + serde::Serialize + Clone + Default + Debug + PartialEq + 'static, - F: FnOnce(String) -> T, -{ - // the active query - let state = use_memo( - |()| { - // initialize with the state from history, properties, or with a reasonable default - gloo_utils::history() - .state() - .ok() - .and_then(|state| { - let deser = state.into_serde::>(); - log::debug!("Deserialized: {deser:?}"); - deser.ok() - }) - .or_else(|| { - props_query.and_then(|s| { - log::debug!("Initial: {s}"); - match s.is_empty() { - true => None, - false => Some(SearchViewState { - search: f(s), - pagination: PaginationControl { - per_page: DEFAULT_PAGE_SIZE, - ..Default::default() - }, - }), - } - }) - }) - .unwrap_or_default() - }, - (), - ); - - let search_params = use_state_eq(|| state.search.clone()); - let pagination = use_pagination(total, || state.pagination); - - // when the search params or pagination state changes, store in history API - use_effect_with_deps( - |(search_params, pagination)| { - // store changes to the state in the current history - if let Ok(data) = JsValue::from_serde(&SearchViewState { - search: search_params, - pagination: *pagination, - }) { - let _ = gloo_utils::history().replace_state(&data, ""); - } - }, - ((*search_params).clone(), pagination.state.control), - ); - - (search_params, pagination) -} - #[derive(Clone)] pub struct UseStandardSearch { pub search_params: UseStateHandle>,