templates.rs (3301B)
1 use askama::Template; 2 3 use crate::database::{Category, CommentWithMeta, StoryWithMeta, UserProfile}; 4 use crate::database::SearchResult; 5 6 #[derive(Template)] 7 #[template(path = "application.html")] 8 pub struct ApplicationTemplate { 9 pub content: String, 10 } 11 12 #[derive(Template)] 13 #[template(path = "feed.html")] 14 pub struct FeedTemplate { 15 pub stories: Vec<StoryWithMeta>, 16 pub tags: Vec<Category>, 17 pub page: usize, 18 pub tag_id: Option<i64>, 19 pub reached_end: bool, 20 pub sort: String, 21 pub is_logged_in: bool, 22 } 23 24 #[derive(Template)] 25 #[template(path = "story.html")] 26 pub struct StoryTemplate { 27 pub story: StoryWithMeta, 28 pub comments: Vec<CommentWithMeta>, 29 pub is_logged_in: bool, 30 pub current_user_id: Option<String>, 31 } 32 33 #[derive(Template)] 34 #[template(path = "comments.html")] 35 pub struct CommentsTemplate { 36 pub comments: Vec<CommentWithMeta>, 37 pub is_logged_in: bool, 38 } 39 40 #[derive(Template)] 41 #[template(path = "submit.html")] 42 pub struct SubmitTemplate { 43 pub error: Option<String>, 44 pub title: String, 45 pub url: String, 46 pub text: String, 47 pub all_tags: Vec<Category>, 48 pub selected_tags: Vec<i64>, 49 } 50 51 #[derive(Template)] 52 #[template(path = "edit.html")] 53 pub struct EditTemplate { 54 pub error: Option<String>, 55 pub story_id: i64, 56 pub title: String, 57 pub url: String, 58 pub text: String, 59 pub all_tags: Vec<Category>, 60 pub selected_tags: Vec<i64>, 61 } 62 63 #[derive(Template)] 64 #[template(path = "reply_form.html")] 65 pub struct ReplyFormTemplate { 66 pub comment_id: i64, 67 pub story_id: i64, 68 pub parent_text: String, 69 pub parent_author: Option<String>, 70 pub error: Option<String>, 71 } 72 73 #[derive(Template)] 74 #[template(path = "vote_button.html")] 75 pub struct VoteButtonTemplate<'a> { 76 pub target_type: &'a str, 77 pub target_id: i64, 78 #[allow(dead_code)] 79 pub score: i64, 80 pub voted: bool, 81 } 82 83 #[derive(Template)] 84 #[template(path = "user.html")] 85 pub struct UserTemplate { 86 pub profile: UserProfile, 87 pub submissions: Vec<StoryWithMeta>, 88 pub comments: Vec<CommentWithMeta>, 89 pub tab: String, 90 pub is_logged_in: bool, 91 } 92 93 #[derive(Template)] 94 #[template(path = "tag.html")] 95 pub struct TagTemplate { 96 pub tag_name: String, 97 pub stories: Vec<StoryWithMeta>, 98 pub page: usize, 99 pub reached_end: bool, 100 pub is_logged_in: bool, 101 } 102 103 #[derive(Template)] 104 #[template(path = "search.html")] 105 pub struct SearchTemplate { 106 #[allow(dead_code)] 107 pub is_logged_in: bool, 108 } 109 110 #[derive(Template)] 111 #[template(path = "search_results.html")] 112 pub struct SearchResultsTemplate { 113 pub results: Vec<SearchResult>, 114 } 115 116 #[derive(Template)] 117 #[template(path = "settings_page.html")] 118 pub struct SettingsTemplate { 119 pub tab: String, 120 } 121 122 #[derive(Template)] 123 #[template(path = "settings_tab.html")] 124 pub struct SettingsTabTemplate { 125 pub tab: String, 126 } 127 128 #[derive(Template)] 129 #[template(path = "login.html")] 130 pub struct LoginTemplate { 131 pub error: Option<String>, 132 } 133 134 #[derive(Template)] 135 #[template(path = "register.html")] 136 pub struct RegisterTemplate { 137 pub error: Option<String>, 138 pub username: String, 139 pub email: String, 140 } 141 142 #[derive(Template)] 143 #[template(path = "resend_verification.html")] 144 pub struct ResendVerificationTemplate { 145 pub error: Option<String>, 146 pub message: Option<String>, 147 }