Fix editing of new articles with noscript.
This also generalizes the code. Neat!
This commit is contained in:
parent
0439ca0d8e
commit
e92c9695be
2 changed files with 6 additions and 10 deletions
|
@ -28,6 +28,7 @@ fn title_from_slug(slug: &str) -> String {
|
||||||
pub struct NewArticleResource {
|
pub struct NewArticleResource {
|
||||||
state: State,
|
state: State,
|
||||||
slug: Option<String>,
|
slug: Option<String>,
|
||||||
|
edit: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -39,8 +40,8 @@ struct CreateArticle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewArticleResource {
|
impl NewArticleResource {
|
||||||
pub fn new(state: State, slug: Option<String>) -> Self {
|
pub fn new(state: State, slug: Option<String>, edit: bool) -> Self {
|
||||||
Self { state, slug }
|
Self { state, slug, edit }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,12 +99,7 @@ impl Resource for NewArticleResource {
|
||||||
body: &Template {
|
body: &Template {
|
||||||
revision: NEW,
|
revision: NEW,
|
||||||
last_updated: None,
|
last_updated: None,
|
||||||
|
edit: self.edit,
|
||||||
// Implicitly start in edit-mode when no slug is given. This
|
|
||||||
// currently directly corresponds to the /_new endpoint
|
|
||||||
// TODO: Also start in edit mode when the ?edit query arg is given
|
|
||||||
edit: self.slug.is_none(),
|
|
||||||
|
|
||||||
cancel_url: self.slug.as_ref().map(|x| &**x),
|
cancel_url: self.slug.as_ref().map(|x| &**x),
|
||||||
title: &title,
|
title: &title,
|
||||||
raw: "",
|
raw: "",
|
||||||
|
|
|
@ -198,7 +198,7 @@ impl WikiLookup {
|
||||||
("_diff", Some(tail)) =>
|
("_diff", Some(tail)) =>
|
||||||
self.diff_lookup_f(tail, query),
|
self.diff_lookup_f(tail, query),
|
||||||
("_new", None) =>
|
("_new", None) =>
|
||||||
Box::new(finished(Some(Box::new(NewArticleResource::new(self.state.clone(), None)) as BoxResource))),
|
Box::new(finished(Some(Box::new(NewArticleResource::new(self.state.clone(), None, true)) as BoxResource))),
|
||||||
("_revisions", Some(tail)) =>
|
("_revisions", Some(tail)) =>
|
||||||
self.revisions_lookup(tail, query),
|
self.revisions_lookup(tail, query),
|
||||||
("_search", None) =>
|
("_search", None) =>
|
||||||
|
@ -236,7 +236,7 @@ impl WikiLookup {
|
||||||
Box::new(self.state.lookup_slug(slug.clone())
|
Box::new(self.state.lookup_slug(slug.clone())
|
||||||
.and_then(move |x| Ok(Some(match x {
|
.and_then(move |x| Ok(Some(match x {
|
||||||
SlugLookup::Miss =>
|
SlugLookup::Miss =>
|
||||||
Box::new(NewArticleResource::new(state, Some(slug))) as BoxResource,
|
Box::new(NewArticleResource::new(state, Some(slug), edit)) as BoxResource,
|
||||||
SlugLookup::Hit { article_id, revision } =>
|
SlugLookup::Hit { article_id, revision } =>
|
||||||
Box::new(ArticleResource::new(state, article_id, revision, edit)) as BoxResource,
|
Box::new(ArticleResource::new(state, article_id, revision, edit)) as BoxResource,
|
||||||
SlugLookup::Redirect(slug) =>
|
SlugLookup::Redirect(slug) =>
|
||||||
|
|
Loading…
Reference in a new issue