diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-04 23:38:21 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-04 23:38:21 -0400 |
| commit | 6366fb3c96e4ed281e233279c85bbfd90ab3ecbc (patch) | |
| tree | bb46e2f9d42d6085517767ed7d53a47885a30345 /src/index.rs | |
| parent | beeb40acdc07d5652bf2128ecb8f71a1116993ae (diff) | |
Support joining channels.
Diffstat (limited to 'src/index.rs')
| -rw-r--r-- | src/index.rs | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/index.rs b/src/index.rs index 605d9f6..9de91d5 100644 --- a/src/index.rs +++ b/src/index.rs @@ -16,10 +16,15 @@ async fn index( async fn index_authenticated(db: SqlitePool, login: Login) -> Result<Markup, InternalError> { let mut tx = db.begin().await?; - let channels = tx.channels().for_login(&login.id).await?; + let joined_channels = tx.channels().joined(&login.id).await?; + let unjoined_channels = tx.channels().unjoined(&login.id).await?; tx.commit().await?; - Ok(templates::authenticated(login, &channels)) + Ok(templates::authenticated( + login, + &joined_channels, + &unjoined_channels, + )) } pub fn router() -> Router<SqlitePool> { @@ -33,7 +38,8 @@ mod templates { pub fn authenticated<'c>( login: Login, - channels: impl IntoIterator<Item = &'c Channel>, + joined_channels: impl IntoIterator<Item = &'c Channel>, + unjoined_channels: impl IntoIterator<Item = &'c Channel>, ) -> Markup { html! { (DOCTYPE) @@ -42,7 +48,8 @@ mod templates { } body { section { - (channel_list(channels)) + (channel_list(joined_channels)) + (join_channel(unjoined_channels)) (create_channel()) } section { @@ -52,21 +59,21 @@ mod templates { } } - fn channel_list<'c>(channels: impl IntoIterator<Item = &'c Channel>) -> Markup { + fn channel_list<'c>(joined_channels: impl IntoIterator<Item = &'c Channel>) -> Markup { html! { ul { - @for channel in channels { - (channel_entry(&channel)) + @for channel in joined_channels { + (joined_channel_entry(&channel)) } } } } - fn channel_entry(channel: &Channel) -> Markup { + fn joined_channel_entry(channel: &Channel) -> Markup { let leave_url = format!("/{}/leave", channel.id); html! { li { - (channel.name) "(" (channel.id) ")" + (channel.name) " (" (channel.id) ")" form action=(leave_url) method="post" { button { "leave" @@ -76,6 +83,24 @@ mod templates { } } + fn join_channel<'c>(unjoined_channels: impl IntoIterator<Item = &'c Channel>) -> Markup { + html! { + form action="join" method="post" { + select name="channel" required { + option value="" { "channel" } + @for channel in unjoined_channels { + option value=(channel.id) { + (channel.name) " (" (channel.id) ")" + } + } + } + button { + "join" + } + } + } + } + fn create_channel() -> Markup { html! { form action="/create" method="post" { |
