uploads/profiles

This commit is contained in:
Robin Appelman 2023-04-16 19:30:52 +02:00
commit d82fb05d68
16 changed files with 276 additions and 24 deletions

View file

@ -1,10 +1,15 @@
use crate::data::demo::Demo;
use crate::data::player::{Player, Team};
use crate::pages::Page;
use demostf_build::Asset;
use itertools::{EitherOrBoth, Itertools};
use maud::{html, Markup};
use std::borrow::Cow;
#[derive(Asset)]
#[asset(source = "style/pages/class-icons.css", url = "/class-icons.css")]
pub struct ClassIconsStyle;
pub struct DemoPage {
pub demo: Demo,
}
@ -15,6 +20,7 @@ impl Page for DemoPage {
}
fn render(&self) -> Markup {
let style_url = ClassIconsStyle::url();
html! {
h2 { (self.demo.server) " - " (self.demo.red) " vs " (self.demo.blu) }
h3 { (self.demo.name) }
@ -111,6 +117,7 @@ impl Page for DemoPage {
}
}
}
link rel="stylesheet" type="text/css" href=(style_url);
}
}
}

View file

@ -53,7 +53,7 @@ impl Page for Index<'_> {
}
}
struct MapList<'a>(&'a [String]);
pub struct MapList<'a>(pub &'a [String]);
impl Render for MapList<'_> {
fn render_to(&self, buffer: &mut String) {

View file

@ -3,7 +3,9 @@ pub mod api;
pub mod demo;
pub mod index;
mod plugin_section;
pub mod profile;
pub mod upload;
pub mod uploads;
use crate::session::SessionData;
use demostf_build::Asset;
@ -23,11 +25,12 @@ pub fn render<T: Page>(page: T, session: SessionData) -> Markup {
let style_url = GlobalStyle::url();
html! {
(DOCTYPE)
html {
html lang = "en" {
head {
meta name = "viewport" content = "initial-scale=1,width=device-width";
title { (page.title()) }
link rel="stylesheet" type="text/css" href=(style_url);
link rel="shortcut icon" type="image/svg+xml" href="images/logo.svg";
link rel="shortcut icon" type="image/svg+xml" href="/images/logo.svg";
}
body {
header {

56
src/pages/profile.rs Normal file
View file

@ -0,0 +1,56 @@
use crate::data::demo::ListDemo;
use crate::data::user::User;
use crate::fragments::demo_list::DemoList;
use crate::pages::index::{DemoListScript, MapList};
use crate::pages::Page;
use demostf_build::Asset;
use maud::{html, Markup, Render};
use std::borrow::Cow;
pub struct Profile<'a> {
pub user: User,
pub demos: &'a [ListDemo],
pub maps: &'a [String],
pub api: &'a str,
}
impl<'a> Profile<'a> {
fn map_list(&self) -> impl Render + 'a {
MapList(&self.maps)
}
fn demo_list(&self) -> impl Render + 'a {
DemoList { demos: self.demos }
}
}
impl Page for Profile<'_> {
fn title(&self) -> Cow<'static, str> {
format!("Demos with {} - demos.tf", self.user.name).into()
}
fn render(&self) -> Markup {
let script = DemoListScript::url();
html! {
h1 {
"Demos with "
(self.user.name)
}
#filter-bar data-maps = (self.map_list()) data-api-base = (self.api) {}
table.demolist {
thead {
tr {
th .title { "Title" }
th .format { "Format" }
th .map { "Map" }
th .duration { "Duration" }
th .date { "Date" }
}
}
tbody {
(self.demo_list())
}
}
script defer src = (script) type = "text/javascript" {}
}
}
}

56
src/pages/uploads.rs Normal file
View file

@ -0,0 +1,56 @@
use crate::data::demo::ListDemo;
use crate::data::user::User;
use crate::fragments::demo_list::DemoList;
use crate::pages::index::{DemoListScript, MapList};
use crate::pages::Page;
use demostf_build::Asset;
use maud::{html, Markup, Render};
use std::borrow::Cow;
pub struct Uploads<'a> {
pub user: User,
pub demos: &'a [ListDemo],
pub maps: &'a [String],
pub api: &'a str,
}
impl<'a> Uploads<'a> {
fn map_list(&self) -> impl Render + 'a {
MapList(&self.maps)
}
fn demo_list(&self) -> impl Render + 'a {
DemoList { demos: self.demos }
}
}
impl Page for Uploads<'_> {
fn title(&self) -> Cow<'static, str> {
format!("Uploads by {} - demos.tf", self.user.name).into()
}
fn render(&self) -> Markup {
let script = DemoListScript::url();
html! {
h1 {
"Uploads by "
(self.user.name)
}
#filter-bar data-maps = (self.map_list()) data-api-base = (self.api) {}
table.demolist {
thead {
tr {
th .title { "Title" }
th .format { "Format" }
th .map { "Map" }
th .duration { "Duration" }
th .date { "Date" }
}
}
tbody {
(self.demo_list())
}
}
script defer src = (script) type = "text/javascript" {}
}
}
}