src/global/structs/history.rs
100 lines · 2128 bytes
1use crate::global::{
2 structs::Item,
3 traits::{Collection, CollectionNoId},
4};
5use serde::{Deserialize, Serialize};
6use typemap::Key;
7
8#[derive(Clone, Default, Serialize, Deserialize)]
9pub struct WatchHistory(pub Vec<Item>);
10
11impl Key for WatchHistory {
12 type Value = Self;
13}
14
15impl Collection<Item> for WatchHistory {
16 const INDEX_PATH: &'static str = ".local/share/youtube-tui/watch_history.json";
17
18 fn items(&self) -> &Vec<Item> {
19 &self.0
20 }
21
22 fn items_mut(&mut self) -> &mut Vec<Item> {
23 &mut self.0
24 }
25
26 fn from_items(items: Vec<Item>) -> Self {
27 Self(items)
28 }
29}
30
31#[derive(Clone, Default, Serialize, Deserialize)]
32pub struct SearchHistory(pub Vec<String>);
33
34impl Key for SearchHistory {
35 type Value = Self;
36}
37
38impl CollectionNoId<String> for SearchHistory {
39 const INDEX_PATH: &'static str = ".local/share/youtube-tui/search_history.json";
40
41 fn items(&self) -> &Vec<String> {
42 &self.0
43 }
44
45 fn items_mut(&mut self) -> &mut Vec<String> {
46 &mut self.0
47 }
48
49 fn from_items(items: Vec<String>) -> Self {
50 Self(items)
51 }
52}
53
54#[derive(Clone, Default, Serialize, Deserialize)]
55pub struct CommandHistory(pub Vec<String>);
56
57impl Key for CommandHistory {
58 type Value = Self;
59}
60
61impl CollectionNoId<String> for CommandHistory {
62 const INDEX_PATH: &'static str = ".local/share/youtube-tui/command_history.json";
63
64 fn items(&self) -> &Vec<String> {
65 &self.0
66 }
67
68 fn items_mut(&mut self) -> &mut Vec<String> {
69 &mut self.0
70 }
71
72 fn from_items(items: Vec<String>) -> Self {
73 Self(items)
74 }
75}
76
77/*
78#[derive(Clone, Default, Serialize, Deserialize)]
79pub struct ChannelHistory(pub Vec<String>);
80
81impl Key for ChannelHistory {
82 type Value = Self;
83}
84
85impl CollectionNoId<String> for ChannelHistory {
86 const INDEX_PATH: &'static str = ".local/share/youtube-tui/channel_history.json";
87
88 fn items(&self) -> &Vec<String> {
89 &self.0
90 }
91
92 fn items_mut(&mut self) -> &mut Vec<String> {
93 &mut self.0
94 }
95
96 fn from_items(items: Vec<String>) -> Self {
97 Self(items)
98 }
99}
100*/