add credentials screen

This commit is contained in:
jfmonty2 committed 2026-11-19 20:26:56 -05:00
1 parent b1c8762981
commit 31edd55b0a
5 files changed
+206 -5

No files matched your search

+132
View File
@@ -0,0 +1,132 @@
use gpui_kit::{
Context, FontWeight, InteractiveElement, IntoElement, ParentElement, Render, SharedString,
Styled, TestSupportExt, Window, div, rems,
};
use gpui_omarchy::{
ActiveTheme, ButtonVariant, ChoiceItem, IconName, empty_state, focus_scope, icon_button,
tab_list,
};
use crate::components::error_alert;
use crate::credentials::AwsCredential;
use crate::session::AppSession;
use super::Screen;
pub struct CredentialsScreen {
tab: usize,
aws: Vec<(String, AwsCredential)>,
error: Option<SharedString>,
}
impl CredentialsScreen {
pub fn new(cx: &mut Context<Self>) -> Self {
let AppSession::Unlocked(db) = cx.global::<AppSession>() else {
unreachable!("credentials screen is only shown while unlocked");
};
let (aws, error) = match db.list_aws_credentials() {
Ok(creds) => {
let mut creds: Vec<_> = creds.into_iter().collect();
creds.sort_by(|a, b| a.0.cmp(&b.0));
(creds, None)
},
Err(e) => (Vec::new(), Some(format!("Failed to load credentials: {e}").into())),
};
Self { tab: 0, aws, error }
}
}
impl Render for CredentialsScreen {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let t = cx.omarchy().clone();
let this = cx.entity();
let tabs = tab_list(
"credential-tabs",
vec![
ChoiceItem::new("aws", "AWS"),
ChoiceItem::new("ssh", "SSH"),
ChoiceItem::new("docker", "Docker"),
],
Some(self.tab),
false,
move |index, _, cx| this.update(cx, |this, cx| {
this.tab = index;
cx.notify();
}),
window,
cx,
);
let panel = match self.tab {
0 if self.aws.is_empty() => empty_state(
"AWS access keys",
"You have no saved AWS credentials.",
cx,
),
0 => div()
.flex()
.flex_col()
.gap(rems(0.5))
.children(self.aws.iter().map(|(name, cred)| {
div()
.id(SharedString::from(name))
.test_support()
.flex()
.justify_between()
.p(rems(0.625))
.border_1()
.border_color(t.border)
.child(div().font_weight(FontWeight::BOLD).child(name.clone()))
.child(
div()
.font_family(t.mono_font.clone())
.text_color(t.secondary)
.child(cred.access_key_id.clone()),
)
})),
1 => empty_state("SSH keys", "Not implemented yet.", cx),
_ => empty_state("Docker credentials", "Not implemented yet.", cx),
};
focus_scope("credentials-screen")
.size_full()
.flex()
.flex_col()
.items_center()
.gap(rems(1.))
.p(rems(0.5))
.child(
div()
.relative()
.w_full()
.flex()
.justify_center()
.child(
icon_button("back", IconName::ChevronLeft, "Back", ButtonVariant::Secondary, cx)
.absolute()
.left_0()
.on_click(|_, _, cx| cx.set_global(Screen::Home)),
)
.child(
div()
.text_size(rems(1.875))
.font_weight(FontWeight::BOLD)
.child("Credentials"),
),
)
.child(tabs)
.child(
div()
.w_full()
.max_w(rems(36.))
.flex()
.flex_col()
.gap(rems(1.))
.children(self.error.clone().map(|e| error_alert(e, cx)))
.child(panel),
)
}
}
+4
View File
@@ -6,6 +6,7 @@ use gpui_kit::{
use gpui_omarchy::{ActiveTheme, IconName, focus_scope, icon};
use crate::session::AppSession;
use super::Screen;
pub struct HomeScreen {}
@@ -13,6 +14,8 @@ pub struct HomeScreen {}
impl Render for HomeScreen {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let t = cx.omarchy();
let credentials = nav_tile("credentials", IconName::Key, "Credentials", "Add, remove, and change credentials.", t.success, cx)
.on_click(|_, _, cx| cx.set_global(Screen::Credentials));
let lock = nav_tile("lock", IconName::ShieldCheck, "Lock", "Lock Creddy.", t.warning, cx)
.on_click(|_, _, cx| cx.set_global(AppSession::Locked));
let exit = nav_tile("exit", IconName::LogOut, "Exit", "Close Creddy.", t.accent, cx)
@@ -37,6 +40,7 @@ impl Render for HomeScreen {
.flex()
.items_center()
.gap(rems(1.5))
.child(credentials)
.child(lock)
.child(exit),
)
+14
View File
@@ -1,7 +1,21 @@
use gpui_kit::Global;
mod credentials;
mod home;
mod unlock;
mod welcome;
pub use credentials::CredentialsScreen;
pub use home::HomeScreen;
pub use unlock::UnlockScreen;
pub use welcome::WelcomeScreen;
/// Which screen to show while the app is unlocked.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Screen {
Home,
Credentials,
}
impl Global for Screen {}