Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions headlines/src/headlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ impl Default for HeadlinesConfig {
pub struct Headlines {
pub articles: Vec<NewsCardData>,
pub config: HeadlinesConfig,
pub api_key_initialized: bool,
pub toggle_config: bool,
pub toggle_about: bool,
pub news_rx: Option<Receiver<NewsCardData>>,
Expand All @@ -64,7 +63,7 @@ impl Headlines {
pub fn init(mut self, cc: &CreationContext) -> Self {
if let Some(storage) = cc.storage {
self.config = eframe::get_value(storage, APP_NAME).unwrap_or_default();
self.api_key_initialized = !self.config.api_key.is_empty();
self.toggle_config = self.config.api_key.is_empty();
}

let api_key = self.config.api_key.to_string();
Expand All @@ -73,7 +72,6 @@ impl Headlines {
#[allow(unused_mut)]
let (mut news_tx, news_rx) = channel();
self.news_rx = Some(news_rx);
self.toggle_config = false;

#[cfg(not(target_arch = "wasm32"))]
{
Expand Down Expand Up @@ -264,11 +262,11 @@ impl Headlines {
toggle_config,
config,
app_tx,
api_key_initialized,
..
} = self;
let mut show_config = *toggle_config;
Window::new("App configuration")
.open(toggle_config)
.open(&mut show_config)
.show(ctx, |ui| {
ui.label("Enter you API_KEY for newsapi.org");
let text_input = ui.text_edit_singleline(&mut config.api_key);
Expand All @@ -277,13 +275,14 @@ impl Headlines {
tx.send(Msg::ApiKeySet(config.api_key.to_string()))
.expect("Failed sending ApiKeySet event");
}
*api_key_initialized = true;
*toggle_config = false;
tracing::info!("API_KEY set");
ui.close_menu();
}
ui.label("Don't have the API_KEY? register at:");
ui.hyperlink("https://newsapi.org/register");
});
*toggle_config &= show_config;
});
}

Expand Down
2 changes: 1 addition & 1 deletion headlines/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl App for Headlines {
return;
}

if self.toggle_config || !self.api_key_initialized {
if self.toggle_config {
self.render_config(ctx);
} else {
self.preload_articles();
Expand Down