Skip to content

Commit

Permalink
improv: add password dialog to access repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Oct 3, 2024
1 parent c32c138 commit 6be9cb2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
1 change: 1 addition & 0 deletions i18n/en/stellarshot.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ loading-snapshots = Loading snapshots.
# Dialogs
save = Save
ok = Ok
create = Create
delete = Delete
cancel = Cancel
Expand Down
46 changes: 37 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub enum Message {
OpenCreateSnapshotDialog(Vec<Url>),
DeleteRepositoryDialog,
RequestFilesForSnapshot,
OpenPasswordDialog(Repository),
}

#[derive(Debug, Clone)]
Expand All @@ -95,6 +96,7 @@ impl ContextPage {

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum DialogPage {
Password(Repository, String),
CreateRepository(String, String),
CreateSnapshot(Vec<Url>, String),
DeleteRepository,
Expand Down Expand Up @@ -256,9 +258,7 @@ impl Application for App {
}

if let Some(repository) = app.nav_model.active_data::<Repository>() {
commands.push(app.update(Message::Content(content::Message::SetRepository(
repository.clone(),
))));
commands.push(app.update(Message::OpenPasswordDialog(repository.clone())));
}

(app, Command::batch(commands))
Expand Down Expand Up @@ -306,6 +306,7 @@ impl Application for App {
password,
))
})
.on_submit(Message::DialogComplete)
.into(),
])
.spacing(spacing.space_xxs),
Expand All @@ -330,7 +331,8 @@ impl Application for App {
files.clone(),
password,
))
}),
})
.on_submit(Message::DialogComplete),
)
.spacing(spacing.space_xxs),
)
Expand All @@ -341,6 +343,27 @@ impl Application for App {
.secondary_action(
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
),
DialogPage::Password(repository, password) => widget::dialog(fl!("password"))
.primary_action(
widget::button::suggested(fl!("ok"))
.on_press_maybe(Some(Message::DialogComplete)),
)
.secondary_action(
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
)
.control(
widget::text_input("", password)
.password()
.label("Password")
.id(self.dialog_text_input.clone())
.on_input(move |password| {
Message::DialogUpdate(DialogPage::Password(
repository.clone(),
password,
))
})
.on_submit(Message::DialogComplete),
),
DialogPage::DeleteRepository => widget::dialog(fl!("delete-repository"))
.body(fl!("delete-repository-description"))
.primary_action(
Expand All @@ -362,11 +385,7 @@ impl Application for App {
if let Some(repository) = self.nav_model.data::<Repository>(entity) {
println!("Selected: {:?}", repository);
let name = repository.name.clone();
commands.push(
self.update(Message::Content(content::Message::SetRepository(
repository.clone(),
))),
);
commands.push(self.update(Message::OpenPasswordDialog(repository.clone())));
let window_title = format!("{} - {}", name, fl!("stellarshot"));
commands.push(self.set_window_title(window_title, self.main_window_id()));
}
Expand Down Expand Up @@ -572,6 +591,10 @@ impl Application for App {
self.dialog_pages
.push_back(DialogPage::CreateSnapshot(files, String::new()));
}
Message::OpenPasswordDialog(repository) => {
self.dialog_pages
.push_back(DialogPage::Password(repository, String::new()));
}
Message::Repository(state) => match state {
RepositoryAction::Init(path, password) => {
let init_path = path.clone();
Expand Down Expand Up @@ -646,6 +669,11 @@ impl Application for App {
DialogPage::CreateSnapshot(files, password) => {
return self.update(Message::CreateSnapshot(files, password));
}
DialogPage::Password(repository, password) => {
return self.update(Message::Content(content::Message::SetRepository(
repository, password,
)));
}
DialogPage::DeleteRepository => {
if let Some(repository) = self.content.repository.clone() {
if let Ok(_) = std::fs::remove_dir_all(&repository.path) {
Expand Down
17 changes: 10 additions & 7 deletions src/app/views/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ use crate::{
pub struct Content {
pub repository: Option<Repository>,
snapshots: Option<Vec<SnapshotFile>>,
password: String,
}

#[derive(Debug, Clone)]
pub enum Message {
SetRepository(Repository),
SetRepository(Repository, String),
SetSnapshots(Vec<SnapshotFile>),
ReloadSnapshots,
Delete(Id),
Delete(Id, String),
Select(Id),
}

Expand All @@ -37,6 +38,7 @@ impl Content {
Self {
repository: None,
snapshots: None,
password: String::new(),
}
}

Expand Down Expand Up @@ -81,16 +83,17 @@ impl Content {
pub fn update(&mut self, message: Message) -> Vec<Command> {
let mut commands = vec![];
match message {
Message::SetRepository(repository) => {
Message::SetRepository(repository, password) => {
self.password = password;
self.snapshots = None;
self.repository = Some(repository.clone());
let path = repository.path.display().to_string();
commands.push(Command::FetchSnapshots(path, "password".into()))
commands.push(Command::FetchSnapshots(path, self.password.clone()))
}
Message::SetSnapshots(snapshots) => self.snapshots = Some(snapshots),
Message::Delete(id) => {
Message::Delete(id, password) => {
let path = self.repository.as_ref().unwrap().path.display().to_string();
commands.push(Command::DeleteSnapshots(path, "password".into(), vec![id]))
commands.push(Command::DeleteSnapshots(path, password, vec![id]))
}
Message::Select(_) => todo!(),
Message::ReloadSnapshots => {
Expand Down Expand Up @@ -118,7 +121,7 @@ impl Content {
let delete_button = widget::button(IconCache::get("user-trash-full-symbolic", 18))
.padding(spacing.space_xxs)
.style(theme::Button::Destructive)
.on_press(Message::Delete(item.id));
.on_press(Message::Delete(item.id, self.password.clone()));

let _details_button = widget::button(IconCache::get("info-outline-symbolic", 18))
.padding(spacing.space_xxs)
Expand Down

0 comments on commit 6be9cb2

Please sign in to comment.