lib: Fix profile loading in context

This commit is contained in:
Erik Kundt
2024-01-19 13:23:26 +01:00
parent b5ccd3f297
commit c61d29ed96
3 changed files with 24 additions and 22 deletions
+1 -1
View File
@@ -182,7 +182,7 @@ impl App {
description,
})) => match self.create_issue(title, description, tags, assignees) {
Ok(id) => {
self.context.reload();
self.context.reload_issues();
Ok(Some(Message::Batch(vec![
Message::Issue(IssueMessage::HideForm),
+2 -1
View File
@@ -120,7 +120,8 @@ pub fn run(options: Options, _ctx: impl terminal::Context) -> anyhow::Result<()>
match options.op {
Operation::Select { opts } => {
let context = context::Context::new(id)?.with_patches();
let profile = terminal::profile()?;
let context = context::Context::new(profile, id)?.with_patches();
log::enable(context.profile(), "patch", "select")?;
+21 -20
View File
@@ -33,6 +33,8 @@ impl Display for Rev {
}
}
/// Application context that holds all the project data that are
/// needed to render it.
pub struct Context {
profile: Profile,
id: Id,
@@ -44,8 +46,7 @@ pub struct Context {
}
impl Context {
pub fn new(id: Id) -> Result<Self, anyhow::Error> {
let profile = profile()?;
pub fn new(profile: Profile, id: Id) -> Result<Self, anyhow::Error> {
let repository = profile.storage.repository(id).unwrap();
let project = repository.identity_doc()?.project()?;
let issues = None;
@@ -53,8 +54,8 @@ impl Context {
let signer = None;
Ok(Self {
id,
profile,
id,
project,
repository,
issues,
@@ -109,26 +110,26 @@ impl Context {
&self.signer
}
pub fn reload(&mut self) {
use crate::cob::issue;
// pub fn reload(&mut self) {
// use crate::cob::issue;
// use crate::cob::patch;
// if self.issues.is_some() {
// self.issues = Some(issue::all(&self.repository).unwrap_or_default());
// }
// if self.patches.is_some() {
// self.patches = Some(patch::all(&self.repository).unwrap_or_default());
// }
// }
pub fn reload_patches(&mut self) {
use crate::cob::patch;
if self.issues.is_some() {
self.issues = Some(issue::all(&self.repository).unwrap_or_default());
}
if self.patches.is_some() {
self.patches = Some(patch::all(&self.repository).unwrap_or_default());
}
self.patches = Some(patch::all(&self.repository).unwrap_or_default());
}
}
/// Get the default profile. Fails if there is no profile.
fn profile() -> Result<Profile, anyhow::Error> {
match Profile::load() {
Ok(profile) => Ok(profile),
Err(_) => Err(anyhow::anyhow!(
"Could not load radicle profile. To setup your radicle profile, run `rad auth`."
)),
pub fn reload_issues(&mut self) {
use crate::cob::issue;
self.issues = Some(issue::all(&self.repository).unwrap_or_default());
}
}