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 {
|
||||
state: State,
|
||||
slug: Option<String>,
|
||||
edit: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -39,8 +40,8 @@ struct CreateArticle {
|
|||
}
|
||||
|
||||
impl NewArticleResource {
|
||||
pub fn new(state: State, slug: Option<String>) -> Self {
|
||||
Self { state, slug }
|
||||
pub fn new(state: State, slug: Option<String>, edit: bool) -> Self {
|
||||
Self { state, slug, edit }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,12 +99,7 @@ impl Resource for NewArticleResource {
|
|||
body: &Template {
|
||||
revision: NEW,
|
||||
last_updated: None,
|
||||
|
||||
// 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(),
|
||||
|
||||
edit: self.edit,
|
||||
cancel_url: self.slug.as_ref().map(|x| &**x),
|
||||
title: &title,
|
||||
raw: "",
|
||||
|
|
|
@ -198,7 +198,7 @@ impl WikiLookup {
|
|||
("_diff", Some(tail)) =>
|
||||
self.diff_lookup_f(tail, query),
|
||||
("_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)) =>
|
||||
self.revisions_lookup(tail, query),
|
||||
("_search", None) =>
|
||||
|
@ -236,7 +236,7 @@ impl WikiLookup {
|
|||
Box::new(self.state.lookup_slug(slug.clone())
|
||||
.and_then(move |x| Ok(Some(match x {
|
||||
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 } =>
|
||||
Box::new(ArticleResource::new(state, article_id, revision, edit)) as BoxResource,
|
||||
SlugLookup::Redirect(slug) =>
|
||||
|
|
Loading…
Reference in a new issue