Skip to content

Commit

Permalink
πŸ“ Apply project and task edits
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanuraj committed Dec 11, 2024
1 parent 3b2a552 commit 48f2c5c
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/commands/edit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::api::client::ApiClient;
use crate::models;
use crate::constants::DEFAULT_ENTITY_ID;
use crate::models::{self, TimeEntry};
use crate::parcel::Parcel;
use crate::picker;
use colored::Colorize;
Expand All @@ -18,12 +19,38 @@ impl EditCommand {
match entities.running_time_entry() {
None => println!("{}", "No time entry is running at the moment".yellow()),
Some(running_time_entry) => {
let updated_time_entry = running_time_entry
.launch_in_editor()
.inspect_err(|e| {
eprintln!("{}", e.to_string().red());
})
.unwrap();
let updated_time_entry = {
let workspace_id = running_time_entry.workspace_id;

let new_entry = running_time_entry
.launch_in_editor()
.inspect_err(|e| {
eprintln!("{}", e.to_string().red());
})
.unwrap();

let project = new_entry.project.and_then(|project| {
if project.id == DEFAULT_ENTITY_ID {
entities.project_for_name(workspace_id, &project.name)
} else {
Some(project)
}
});

let task = new_entry.task.and_then(|task| {
if task.id == DEFAULT_ENTITY_ID {
entities.task_for_name(workspace_id, &task.name)
} else {
Some(task)
}
});

TimeEntry {
project,
task,
..new_entry
}
};

let updated_entry_id = api_client
.update_time_entry(updated_time_entry.clone())
Expand Down

0 comments on commit 48f2c5c

Please sign in to comment.