Accounts: support dark theme

This commit is contained in:
asonix 2021-01-09 19:46:31 -06:00
parent 291f567c8e
commit ccf0b98d05
15 changed files with 75 additions and 27 deletions

View file

@ -9,6 +9,7 @@ pub type CookiesArgs = (Session, web::Data<State>);
#[derive(Debug)]
pub struct CookiesState {
state: State,
pub(crate) dark: bool,
}
pub fn cookies_page((cookies, state): CookiesPageArgs) -> Result<CookiesState, HttpResponse> {
@ -29,9 +30,14 @@ impl CookiesState {
fn new(state: &State) -> Self {
CookiesState {
state: state.clone(),
dark: false,
}
}
pub fn dark(&mut self, dark: bool) {
self.dark = dark;
}
pub(crate) fn cookies_path(&self) -> String {
self.state.pages.cookies_path()
}

View file

@ -21,6 +21,7 @@ pub struct DeleteUserState {
state: State,
form: Option<DeleteUserForm>,
error: Option<DeleteUserError>,
pub(crate) dark: bool,
}
pub fn delete_user_page((_, state): DeleteUserPageArgs) -> Result<DeleteUserState, HttpResponse> {
@ -44,6 +45,7 @@ impl DeleteUserState {
state: state.clone(),
form: None,
error: None,
dark: false,
}
}
@ -52,9 +54,14 @@ impl DeleteUserState {
state: state.clone(),
form: form.into(),
error: error.into(),
dark: false,
}
}
pub fn dark(&mut self, dark: bool) {
self.dark = dark;
}
pub(crate) fn delete_user_path(&self) -> String {
self.state.pages.delete_user_path()
}

View file

@ -27,6 +27,7 @@ pub struct LoginState {
state: State,
form: Option<LoginForm>,
error: Option<LoginError>,
pub(crate) dark: bool,
}
pub fn login_page(
@ -63,11 +64,16 @@ pub async fn login(
}
impl LoginState {
pub fn dark(&mut self, dark: bool) {
self.dark = dark;
}
fn new_empty(state: &State) -> Self {
LoginState {
state: state.clone(),
form: None,
error: None,
dark: false,
}
}
@ -76,6 +82,7 @@ impl LoginState {
state: state.clone(),
form: Some(form),
error: Some(error),
dark: false,
}
}

View file

@ -10,6 +10,7 @@ pub type LogoutArgs = (Authenticated, web::Data<State>, Session);
#[derive(Clone)]
pub struct LogoutState {
state: State,
pub(crate) dark: bool,
}
pub fn logout_page((_, state): LogoutPageArgs) -> LogoutState {
@ -26,9 +27,15 @@ impl LogoutState {
fn new(state: &State) -> Self {
LogoutState {
state: state.clone(),
dark: false,
}
}
pub fn dark(&mut self, dark: bool) -> &mut Self {
self.dark = dark;
self
}
pub fn button<'a>(&self, btn: &'a hyaenidae_toolkit::Button) -> &'a hyaenidae_toolkit::Button {
btn.form(&self.logout_path())
}

View file

@ -28,6 +28,7 @@ pub struct RegisterState {
state: State,
form: Option<RegisterForm>,
error: Option<RegisterError>,
pub(crate) dark: bool,
}
pub fn register_page(
@ -69,6 +70,7 @@ impl RegisterState {
state: state.clone(),
form: None,
error: None,
dark: false,
}
}
@ -77,9 +79,14 @@ impl RegisterState {
state: state.clone(),
form: Some(form),
error: Some(error),
dark: false,
}
}
pub fn dark(&mut self, dark: bool) {
self.dark = dark;
}
pub(crate) fn register_path(&self) -> String {
self.state.pages.register_path()
}

View file

@ -21,6 +21,7 @@ pub struct UpdatePasswordState {
state: State,
form: Option<UpdatePasswordForm>,
error: Option<UpdatePasswordError>,
pub(crate) dark: bool,
}
pub fn update_password_page((_, state): UpdatePasswordPageArgs) -> UpdatePasswordState {
@ -44,6 +45,7 @@ impl UpdatePasswordState {
state: state.clone(),
form: None,
error: None,
dark: false,
}
}
@ -56,9 +58,14 @@ impl UpdatePasswordState {
state: state.clone(),
form: Some(form),
error: Some(error),
dark: false,
}
}
pub fn dark(&mut self, dark: bool) {
self.dark = dark;
}
pub(crate) fn update_password_path(&self) -> String {
self.state.pages.update_password_path()
}

View file

@ -20,6 +20,7 @@ pub struct UpdateUsernameState {
state: State,
form: Option<UpdateUsernameForm>,
error: Option<UpdateUsernameError>,
pub(crate) dark: bool,
}
pub fn update_username_page((_, state): UpdateUsernamePageArgs) -> UpdateUsernameState {
@ -43,6 +44,7 @@ impl UpdateUsernameState {
state: state.clone(),
form: None,
error: None,
dark: false,
}
}
@ -55,9 +57,14 @@ impl UpdateUsernameState {
state: state.clone(),
form: Some(form),
error: Some(error),
dark: false,
}
}
pub fn dark(&mut self, dark: bool) {
self.dark = dark;
}
pub(crate) fn update_username_path(&self) -> String {
self.state.pages.update_username_path()
}

View file

@ -11,8 +11,8 @@
@:card_body({
<form method="POST" action="@state.cookies_path()">
@:button_group(&[
&Button::primary("Accept Cookies"),
Button::primary_outline("Cancel").href(&state.home_path()),
&Button::primary("Accept Cookies").dark(state.dark),
Button::primary_outline("Cancel").href(&state.home_path()).dark(state.dark),
])
</form>
})

View file

@ -8,12 +8,12 @@
<form method="POST" action="@state.delete_user_path()">
@:card_title({ Delete Account })
@:card_body({
@:password_input("password", "Password", state.password(), state.password_error())
@:password_input("password", "Password", state.password(), state.password_error(), state.dark)
})
@:card_body({
@:button_group(&[
&Button::primary("Delete Account"),
Button::primary_outline("Cancel").href(&state.accounts_path())
&Button::primary("Delete Account").dark(state.dark),
Button::primary_outline("Cancel").href(&state.accounts_path()).dark(state.dark),
])
})
</form>

View file

@ -1,5 +1,5 @@
@use hyaenidae_toolkit::{templates::text_input, TextInput};
@(name: &str, title: &str, value: Option<String>, error: Option<String>)
@(name: &str, title: &str, value: Option<String>, error: Option<String>, dark: bool)
@:text_input(TextInput::new(name).title(title).value_opt(value).error_opt(error).password())
@:text_input(TextInput::new(name).title(title).value_opt(value).error_opt(error).password().dark(dark))

View file

@ -1,5 +1,5 @@
@use hyaenidae_toolkit::{templates::text_input, TextInput};
@(name: &str, title: &str, value: Option<String>, error: Option<String>)
@(name: &str, title: &str, value: Option<String>, error: Option<String>, dark:bool)
@:text_input(TextInput::new(name).title(title).value_opt(value).error_opt(error))
@:text_input(TextInput::new(name).title(title).value_opt(value).error_opt(error).dark(dark))

View file

@ -8,14 +8,14 @@
<form method="POST" action="@state.login_path()">
@:card_title({ Login })
@:card_body({
@:text_input("username", "Username", state.username(), state.username_error())
@:password_input("password", "Password", state.password(), None)
@:link(&Link::current_tab(&state.register_path()), { I do not have an account })
@:text_input("username", "Username", state.username(), state.username_error(), state.dark)
@:password_input("password", "Password", state.password(), None, state.dark)
@:link(&Link::current_tab(&state.register_path()).dark(state.dark), { I do not have an account })
})
@:card_body({
@:button_group(&[
&Button::primary("Login"),
Button::primary_outline("Cancel").href(&state.home_path()),
&Button::primary("Login").dark(state.dark),
Button::primary_outline("Cancel").href(&state.home_path()).dark(state.dark),
])
})
</form>

View file

@ -8,15 +8,15 @@
<form method="POST" action="@state.register_path()">
@:card_title({ Register })
@:card_body({
@:text_input("username", "Username", state.username(), state.username_error())
@:password_input("password", "Password", state.password(), None)
@:password_input("password_confirmation", "Password Confirmation", state.confirmation(), state.confirmation_error())
@:link(&Link::current_tab(&state.login_path()), { I already have an account })
@:text_input("username", "Username", state.username(), state.username_error(), state.dark)
@:password_input("password", "Password", state.password(), None, state.dark)
@:password_input("password_confirmation", "Password Confirmation", state.confirmation(), state.confirmation_error(), state.dark)
@:link(&Link::current_tab(&state.login_path()).dark(state.dark), { I already have an account })
})
@:card_body({
@:button_group(&[
&Button::primary("Register"),
Button::primary_outline("Cancel").href(&state.home_path()),
&Button::primary("Register").dark(state.dark),
Button::primary_outline("Cancel").href(&state.home_path()).dark(state.dark),
])
})
</form>

View file

@ -8,12 +8,12 @@
<form method="POST" action="@state.update_password_path()">
@:card_title({ Update Password })
@:card_body({
@:password_input("new_password", "New Password", state.new_password(), None)
@:password_input("new_password_confirmation", "New Password Confirmation", state.new_password_confirmation(), state.new_password_confirmation_error())
@:password_input("password", "Password", state.password(), state.password_error())
@:password_input("new_password", "New Password", state.new_password(), None, state.dark)
@:password_input("new_password_confirmation", "New Password Confirmation", state.new_password_confirmation(), state.new_password_confirmation_error(), state.dark)
@:password_input("password", "Password", state.password(), state.password_error(), state.dark)
})
@:card_body({
@:button_group(&[&Button::primary("Update Password")])
@:button_group(&[&Button::primary("Update Password").dark(state.dark)])
})
</form>
})

View file

@ -8,11 +8,11 @@
<form method="POST" action="@state.update_username_path()">
@:card_title({ Update Username })
@:card_body({
@:text_input("new_username", "New Username", state.username(), state.username_error())
@:password_input("password", "Password", state.password(), state.password_error())
@:text_input("new_username", "New Username", state.username(), state.username_error(), state.dark)
@:password_input("password", "Password", state.password(), state.password_error(), state.dark)
})
@:card_body({
@:button_group(&[&Button::primary("Update Username")])
@:button_group(&[&Button::primary("Update Username").dark(state.dark)])
})
</form>
})