Add category suggestions to the post editor.
This commit is contained in:
@@ -11,6 +11,10 @@ impl BdsApp {
|
||||
post_id: String,
|
||||
tag: String,
|
||||
},
|
||||
EnsureCategory {
|
||||
post_id: String,
|
||||
category: String,
|
||||
},
|
||||
LoadSemanticTags(String),
|
||||
AddGalleryImages(String),
|
||||
DetectLanguage(String),
|
||||
@@ -194,9 +198,33 @@ impl BdsApp {
|
||||
}
|
||||
PostEditorMsg::CategoriesInputSubmit => {
|
||||
let cat = state.categories_input.trim().to_string();
|
||||
if !cat.is_empty() && !state.categories.contains(&cat) {
|
||||
state.categories.push(cat);
|
||||
if !cat.is_empty()
|
||||
&& !state
|
||||
.categories
|
||||
.iter()
|
||||
.any(|current| current.eq_ignore_ascii_case(&cat))
|
||||
{
|
||||
state.categories.push(cat.clone());
|
||||
state.mark_dirty();
|
||||
deferred = DeferredPostAction::EnsureCategory {
|
||||
post_id: state.post_id.clone(),
|
||||
category: cat,
|
||||
};
|
||||
}
|
||||
state.categories_input.clear();
|
||||
}
|
||||
PostEditorMsg::AddSuggestedCategory(category) => {
|
||||
if !state
|
||||
.categories
|
||||
.iter()
|
||||
.any(|current| current.eq_ignore_ascii_case(&category))
|
||||
{
|
||||
state.categories.push(category.clone());
|
||||
state.mark_dirty();
|
||||
deferred = DeferredPostAction::EnsureCategory {
|
||||
post_id: state.post_id.clone(),
|
||||
category,
|
||||
};
|
||||
}
|
||||
state.categories_input.clear();
|
||||
}
|
||||
@@ -321,6 +349,9 @@ impl BdsApp {
|
||||
DeferredPostAction::EnsureTag { post_id, tag } => {
|
||||
self.ensure_post_editor_tag(&post_id, &tag)
|
||||
}
|
||||
DeferredPostAction::EnsureCategory { post_id, category } => {
|
||||
self.ensure_post_editor_category(&post_id, &category)
|
||||
}
|
||||
DeferredPostAction::LoadSemanticTags(post_id) => {
|
||||
Task::done(Message::LoadSemanticTagSuggestions(post_id))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user