mirror of
https://github.com/Nutomic/ibis.git
synced 2025-02-11 02:44:40 +00:00
Show warning on edit page if instance hasnt federated in 3 days (fixes #108)
This commit is contained in:
parent
d4c4202281
commit
a2d24862ab
4 changed files with 28 additions and 9 deletions
|
@ -258,9 +258,11 @@ pub(super) async fn resolve_article(
|
|||
data: Data<IbisData>,
|
||||
) -> MyResult<Json<ArticleView>> {
|
||||
let article: DbArticle = ObjectId::from(query.id).dereference(&data).await?;
|
||||
let instance = DbInstance::read(article.instance_id, &data)?;
|
||||
let latest_version = article.latest_edit_version(&data)?;
|
||||
Ok(Json(ArticleView {
|
||||
article,
|
||||
instance,
|
||||
latest_version,
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use crate::{
|
|||
newtypes::{ArticleId, InstanceId},
|
||||
ArticleView,
|
||||
DbArticle,
|
||||
DbInstance,
|
||||
EditVersion,
|
||||
},
|
||||
};
|
||||
|
@ -100,11 +101,15 @@ impl DbArticle {
|
|||
|
||||
pub fn read_view(id: ArticleId, data: &IbisData) -> MyResult<ArticleView> {
|
||||
let mut conn = data.db_pool.get()?;
|
||||
let query = article::table.find(id).into_boxed();
|
||||
let article: DbArticle = query.get_result(conn.deref_mut())?;
|
||||
let query = article::table
|
||||
.find(id)
|
||||
.inner_join(instance::table)
|
||||
.into_boxed();
|
||||
let (article, instance): (DbArticle, DbInstance) = query.get_result(conn.deref_mut())?;
|
||||
let latest_version = article.latest_edit_version(data)?;
|
||||
Ok(ArticleView {
|
||||
article,
|
||||
instance,
|
||||
latest_version,
|
||||
})
|
||||
}
|
||||
|
@ -115,7 +120,7 @@ impl DbArticle {
|
|||
data: &IbisData,
|
||||
) -> MyResult<ArticleView> {
|
||||
let mut conn = data.db_pool.get()?;
|
||||
let article: DbArticle = {
|
||||
let (article, instance): (DbArticle, DbInstance) = {
|
||||
let query = article::table
|
||||
.inner_join(instance::table)
|
||||
.filter(article::dsl::title.eq(title))
|
||||
|
@ -125,13 +130,12 @@ impl DbArticle {
|
|||
} else {
|
||||
query.filter(article::dsl::local.eq(true))
|
||||
};
|
||||
query
|
||||
.select(article::all_columns)
|
||||
.get_result(conn.deref_mut())?
|
||||
query.get_result(conn.deref_mut())?
|
||||
};
|
||||
let latest_version = article.latest_edit_version(data)?;
|
||||
Ok(ArticleView {
|
||||
article,
|
||||
instance,
|
||||
latest_version,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ pub struct ListArticlesForm {
|
|||
#[cfg_attr(feature = "ssr", diesel(table_name = article, check_for_backend(diesel::pg::Pg)))]
|
||||
pub struct ArticleView {
|
||||
pub article: DbArticle,
|
||||
pub instance: DbInstance,
|
||||
pub latest_version: EditVersion,
|
||||
}
|
||||
|
||||
|
@ -319,7 +320,6 @@ pub struct DbInstance {
|
|||
pub public_key: String,
|
||||
#[serde(skip)]
|
||||
pub private_key: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub last_refreshed_at: DateTime<Utc>,
|
||||
pub local: bool,
|
||||
#[cfg(feature = "ssr")]
|
||||
|
|
|
@ -16,6 +16,7 @@ use crate::{
|
|||
pages::article_resource,
|
||||
},
|
||||
};
|
||||
use chrono::{Days, Utc};
|
||||
use leptos::{html::Textarea, prelude::*};
|
||||
use leptos_router::{components::Redirect, hooks::use_params_map};
|
||||
use leptos_use::{use_textarea_autosize, UseTextareaAutosizeReturn};
|
||||
|
@ -142,9 +143,21 @@ pub fn EditArticle() -> impl IntoView {
|
|||
edit_error
|
||||
.get()
|
||||
.map(|err| {
|
||||
view! { <p style="color:red;">{err}</p> }
|
||||
view! { <p class="alert alert-error">{err}</p> }
|
||||
})
|
||||
}} <EditorView textarea_ref content set_content />
|
||||
}}
|
||||
<Show when=move || {
|
||||
article.instance.last_refreshed_at + Days::new(3)
|
||||
< Utc::now()
|
||||
}>
|
||||
<div class="alert alert-warning">
|
||||
This article is hosted on {article.instance.domain.clone()}
|
||||
which hasnt been federated in
|
||||
{(Utc::now() - article.instance.last_refreshed_at)
|
||||
.num_days()}
|
||||
days. Edits will most likely fail. Instead consider forking the article to your local instance (under Actions), or edit a different article.
|
||||
</div>
|
||||
</Show> <EditorView textarea_ref content set_content />
|
||||
<div class="flex flex-row mr-2">
|
||||
<input
|
||||
type="text"
|
||||
|
|
Loading…
Reference in a new issue