make things nice and centered, add base url to guild dashboard links

pull/8/head
Patrick Cleavelin 2023-07-31 23:05:45 -05:00
parent 9d1d0eaecd
commit b1be0d0d77
2 changed files with 94 additions and 76 deletions

View File

@ -23,6 +23,7 @@ pub enum Tag {
Dialog,
Article,
Header,
Footer,
Div,
@ -51,6 +52,7 @@ pub enum Tag {
Anchor,
Button,
HeaderGroup,
Header1,
Header2,
Header3,
@ -85,6 +87,7 @@ impl Tag {
Self::Dialog => "dialog",
Self::Article => "article",
Self::Header => "header",
Self::Footer => "footer",
Self::Div => "div",
@ -111,6 +114,7 @@ impl Tag {
Self::Anchor => "a",
Self::Button => "button",
Self::HeaderGroup => "hgroup",
Self::Header1 => "h1",
Self::Header2 => "h2",
Self::Header3 => "h3",

View File

@ -1,6 +1,6 @@
use crate::{
auth::{self, User},
htmx::{Build, HtmxBuilder, SwapMethod, Tag},
htmx::{Build, HtmxBuilder, Tag},
settings::{ApiState, Intro, IntroFriendlyName},
};
use axum::{
@ -9,11 +9,24 @@ use axum::{
};
use tracing::error;
pub(crate) async fn home(user: Option<User>) -> Redirect {
fn page_header(title: &str) -> HtmxBuilder {
HtmxBuilder::new(Tag::Html).head(|b| {
b.title(title)
.script(
"https://unpkg.com/htmx.org@1.9.3",
Some("sha384-lVb3Rd/Ca0AxaoZg5sACe8FJKF0tnUgR2Kd7ehUOG5GCcROv5uBIZsOqovBAcWua"),
)
// Not currently using
// .script("https://unpkg.com/hyperscript.org@0.9.9", None)
.style_link("https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css")
})
}
pub(crate) async fn home(State(state): State<ApiState>, user: Option<User>) -> Redirect {
if user.is_some() {
Redirect::to("/guild/588149178912473103")
Redirect::to(&format!("{}/guild/588149178912473103", state.origin))
} else {
Redirect::to("/login")
Redirect::to(&format!("{}/login", state.origin))
}
}
@ -29,7 +42,7 @@ fn intro_list<'a>(
.builder(Tag::FieldSet, |b| {
let mut b = b
.attribute("class", "container")
.attribute("style", "max-height: 20%; overflow-y: scroll");
.attribute("style", "max-height: 50%; overflow-y: scroll");
for intro in intros {
b = b.builder(Tag::Label, |b| {
b.builder(Tag::Input, |b| {
@ -54,38 +67,40 @@ pub(crate) async fn guild_dashboard(
let Some(guild) = settings.guilds.get(&guild_id) else {
error!(%guild_id, "no such guild");
return Err(Redirect::to("/"));
return Err(Redirect::to(&format!("{}/", state.origin)));
};
let Some(guild_user) = guild.users.get(&user.name) else {
error!(%guild_id, %user.name, "no user in guild");
return Err(Redirect::to("/"));
return Err(Redirect::to(&format!("{}/", state.origin)));
};
let is_moderator = guild_user.permissions.can(auth::Permission::DeleteSounds);
Ok(Html(
HtmxBuilder::new(Tag::Html)
.head(|b| {
b.title("MemeJoin - Dashboard")
.script(
"https://unpkg.com/htmx.org@1.9.3",
Some("sha384-lVb3Rd/Ca0AxaoZg5sACe8FJKF0tnUgR2Kd7ehUOG5GCcROv5uBIZsOqovBAcWua"),
)
.script("https://unpkg.com/hyperscript.org@0.9.9", None)
.style_link("https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css")
})
.push_builder(page_header("MemeJoin - Dashboard"))
.builder(Tag::Nav, |b| {
b.builder(Tag::Header1, |b| b.text("MemeJoin - A bot for user intros"))
.builder_text(Tag::Paragraph, &user.name)
b.builder(Tag::HeaderGroup, |b| {
b.attribute("class", "container")
.builder(Tag::Header1, |b| b.text("MemeJoin - A bot for user intros"))
.builder_text(Tag::Header6, &user.name)
})
.builder(Tag::Main, |b| {
})
.builder(Tag::Empty, |b| {
if is_moderator {
b.builder(Tag::Article, |b| {
b.builder(Tag::Div, |b| {
b.attribute("class", "container")
.builder(Tag::Article, |b| {
b.builder_text(Tag::Header, "Wow, you're a moderator")
.push_builder(moderator_dashboard())
.builder_text(Tag::Footer, "End of super cool mod section")
})
})
} else {
b
}
.builder(Tag::Div, |b| {
b.attribute("class", "container")
.builder(Tag::Article, |b| {
let mut b = b.builder_text(Tag::Header, "Guild Settings");
@ -98,7 +113,8 @@ pub(crate) async fn guild_dashboard(
guild.intros.get(&intro_index.index)?,
))
});
let available_intros = guild.intros.iter().filter_map(|intro| {
let available_intros =
guild.intros.iter().filter_map(|intro| {
if !channel_user
.intros
.iter()
@ -109,16 +125,16 @@ pub(crate) async fn guild_dashboard(
None
}
});
b = b
.builder_text(Tag::Strong, channel_name)
.builder(Tag::Div, |b| {
b = b.builder_text(Tag::Strong, channel_name).builder(
Tag::Div,
|b| {
b.builder_text(Tag::Strong, "Your Current Intros")
.push_builder(intro_list(
current_intros,
"Remove Intro",
&format!(
"/v2/intros/remove/{}/{}",
guild_id, channel_name
"{}/v2/intros/remove/{}/{}",
state.origin, guild_id, channel_name
),
))
.builder_text(Tag::Strong, "Select Intros")
@ -126,35 +142,33 @@ pub(crate) async fn guild_dashboard(
available_intros,
"Add Intro",
&format!(
"/v2/intros/add/{}/{}",
guild_id, channel_name
"{}/v2/intros/add/{}/{}",
state.origin, guild_id, channel_name
),
))
});
},
);
}
}
b
})
})
})
.build(),
))
}
fn moderator_dashboard() -> HtmxBuilder {
HtmxBuilder::new(Tag::Empty)
}
pub(crate) async fn login(State(state): State<ApiState>) -> Html<String> {
let authorize_uri = format!("https://discord.com/api/oauth2/authorize?client_id={}&redirect_uri={}/v2/auth&response_type=code&scope=guilds.members.read%20guilds%20identify", state.secrets.client_id, state.origin);
Html(
HtmxBuilder::new(Tag::Html)
.head(|b| {
b.title("MemeJoin - Login")
.script(
"https://unpkg.com/htmx.org@1.9.3",
Some("sha384-lVb3Rd/Ca0AxaoZg5sACe8FJKF0tnUgR2Kd7ehUOG5GCcROv5uBIZsOqovBAcWua"),
)
.script("https://unpkg.com/hyperscript.org@0.9.9", None)
.style_link("https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css")
})
.push_builder(page_header("MemeJoin - Login"))
.link("Login", &authorize_uri)
.build(),
)