M src/components/mod.rs => src/components/mod.rs +35 -3
@@ 4,9 4,9 @@ use std::borrow::{Borrow, Cow};
use std::collections::HashMap;
use crate::resp_types::{
- RespCommentInfo, RespMinimalAuthorInfo, RespMinimalCommentInfo, RespMinimalCommunityInfo,
- RespNotification, RespNotificationInfo, RespPostCommentInfo, RespPostInfo, RespPostListPost,
- RespThingComment, RespThingInfo,
+ RespCommentInfo, RespCommunityInfoMaybeYour, RespMinimalAuthorInfo, RespMinimalCommentInfo,
+ RespMinimalCommunityInfo, RespNotification, RespNotificationInfo, RespPostCommentInfo,
+ RespPostInfo, RespPostListPost, RespThingComment, RespThingInfo, RespUserInfo,
};
use crate::util::{abbreviate_link, author_is_me};
use crate::PageBaseData;
@@ 194,6 194,38 @@ impl<'a> HavingContent for RespPostInfo<'a> {
}
}
+pub struct HavingContentRef<'a> {
+ content_html: Option<&'a str>,
+ content_text: Option<&'a str>,
+}
+
+impl<'a> HavingContent for HavingContentRef<'a> {
+ fn content_text(&self) -> Option<&str> {
+ self.content_text
+ }
+ fn content_html(&self) -> Option<&str> {
+ self.content_html
+ }
+}
+
+impl<'a> RespUserInfo<'a> {
+ pub fn description(&'a self) -> HavingContentRef<'a> {
+ HavingContentRef {
+ content_html: self.description_html.as_deref(),
+ content_text: self.description_text.as_deref(),
+ }
+ }
+}
+
+impl<'a> RespCommunityInfoMaybeYour<'a> {
+ pub fn description(&'a self) -> HavingContentRef<'a> {
+ HavingContentRef {
+ content_html: self.description_html.as_deref(),
+ content_text: self.description_text.as_deref(),
+ }
+ }
+}
+
pub struct Content<'a, T: HavingContent + 'a> {
pub src: &'a T,
}
M src/resp_types.rs => src/resp_types.rs +4 -2
@@ 158,7 158,8 @@ pub struct RespMinimalCommunityInfo<'a> {
pub struct RespUserInfo<'a> {
#[serde(flatten)]
pub base: RespMinimalAuthorInfo<'a>,
- pub description: Cow<'a, str>,
+ pub description_html: Option<Cow<'a, str>>,
+ pub description_text: Option<Cow<'a, str>>,
pub suspended: Option<bool>,
pub your_note: Option<JustContentText<'a>>,
}
@@ 204,7 205,8 @@ pub struct RespCommunityInfoMaybeYour<'a> {
#[serde(flatten)]
pub base: RespMinimalCommunityInfo<'a>,
- pub description: Cow<'a, str>,
+ pub description_html: Option<Cow<'a, str>>,
+ pub description_text: Option<Cow<'a, str>>,
pub you_are_moderator: Option<bool>,
pub your_follow: Option<RespYourFollow>,
M src/routes/communities.rs => src/routes/communities.rs +5 -3
@@ 1,4 1,6 @@
-use crate::components::{CommunityLink, HTPage, MaybeFillInput, MaybeFillTextArea, PostItem};
+use crate::components::{
+ CommunityLink, Content, HTPage, MaybeFillInput, MaybeFillTextArea, PostItem,
+};
use crate::resp_types::{
JustContentHTML, JustStringID, RespCommunityInfoMaybeYour, RespMinimalAuthorInfo,
RespMinimalCommunityInfo, RespPostListPost, RespYourFollow,
@@ 229,7 231,7 @@ async fn page_community(
None
}
}
- <p>{community_info.description.as_ref()}</p>
+ <Content src={&community_info.description()} />
{
if community_info.as_ref().local {
Some(render::rsx! {
@@ 333,7 335,7 @@ async fn page_community_edit_inner(
<form method={"POST"} action={format!("/communities/{}/edit/submit", community_id)}>
<label>
{lang.tr("description", None)}{":"}<br />
- <MaybeFillTextArea values={&prev_values} name={"description"} default_value={Some(community_info.description.as_ref())} />
+ <MaybeFillTextArea values={&prev_values} name={"description"} default_value={Some(community_info.description_text.as_deref().unwrap_or(""))} />
</label>
<div>
<button r#type={"submit"}>{lang.tr("submit", None)}</button>
M src/routes/mod.rs => src/routes/mod.rs +2 -2
@@ 1427,7 1427,7 @@ async fn page_user(
None
}
}
- <p>{user.description.as_ref()}</p>
+ <Content src={&user.description()} />
{
if things.is_empty() {
Some(render::rsx! { <p>{lang.tr("nothing", None)}</p> })
@@ 1502,7 1502,7 @@ async fn page_user_edit(
<div>
<label>
{lang.tr("user_edit_description_prompt", None)}<br />
- <textarea name={"description"}>{user.description.as_ref()}</textarea>
+ <textarea name={"description"}>{user.description_text.as_deref().unwrap_or("")}</textarea>
</label>
</div>
<div>