Skip to content

Commit 0fb8df6

Browse files
committed
Working people and tags
1 parent 6a5131c commit 0fb8df6

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

src/components/metadata_form.rs

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,18 @@ async fn handle_form(data: MediaReviewForm) -> Result<(), ServerFnError> {
7474
use crate::models::MediaUpdate;
7575
log!("File within handle_form: {:?}", data.file);
7676
log!("Handling form");
77-
let tag_ids = match handle_tags(data.tags).await {
77+
//combine tags and manual tags
78+
let all_tags = data.tags + "," + &*data.tags_manual;
79+
let tag_ids = match handle_tags(all_tags).await {
7880
Ok(tag_ids) => tag_ids,
7981
Err(e) => {
8082
log!("Error handling tags: {:?}", e);
8183
return Err(e);
8284
}
8385
};
8486
log!("Tag ids: {:?}", tag_ids);
85-
let person_ids = match handle_people(data.people).await {
87+
let all_people = data.people + "," + &*data.people_manual;
88+
let person_ids = match handle_people(all_people).await {
8689
Ok(person_ids) => person_ids,
8790
Err(e) => {
8891
log!("Error handling people: {:?}", e);
@@ -143,6 +146,8 @@ pub fn VideoMetadataForm(
143146
let submit = ServerAction::<HandleForm>::new();
144147
let selected_tags = RwSignal::new(Vec::<String>::new());
145148
let selected_tags_count = RwSignal::new(0);
149+
let selected_people = RwSignal::new(Vec::<String>::new());
150+
let selected_people_count = RwSignal::new(0);
146151
log!("Tags: {:?}", tags);
147152
let current_tags = match tags {
148153
Some(tags) => tags,
@@ -156,6 +161,49 @@ pub fn VideoMetadataForm(
156161
view! {
157162
<div class="form">
158163
<ActionForm action=submit >
164+
165+
<div class="snap-center flex items-center">
166+
<h2 class="inline text-cyan-500 font-extrabold mr-2">People:</h2>
167+
<ul class="inline list-none p-0 m-0 flex gap-2">
168+
{current_people.into_iter().map(|p| {
169+
let person = p.clone();
170+
let person_other = p.clone();
171+
let is_selected = Memo::new(move |_| {
172+
println!("something selected");
173+
selected_people.get().contains(&person)
174+
});
175+
let class_string = move || if is_selected.get() { "p-2 rounded-md bg-accent" } else { "p-2 rounded-md" };
176+
177+
178+
view! {
179+
<div on:click=move |_| {
180+
let person_clone = person_other.clone();
181+
selected_people.update(|selected| {
182+
println!("clicked");
183+
if selected.contains(&person_clone) {
184+
*selected_people_count.write() += -1;
185+
selected.retain(|t| t != &person_clone);
186+
} else {
187+
*selected_people_count.write() += 1;
188+
selected.push(person_clone);
189+
}
190+
});
191+
log!("Selected People: {:?}", selected_people.get());
192+
}
193+
class=class_string style="cursor: pointer;"
194+
>
195+
196+
<span class="pl-3 pr-1">{person_other.clone()}</span>
197+
</div>
198+
199+
200+
201+
}
202+
}).collect::<Vec<_>>()}
203+
</ul>
204+
</div>
205+
206+
159207
<div class="snap-center flex items-center">
160208
<h2 class="inline text-cyan-500 font-extrabold mr-2">Tags:</h2>
161209
<ul class="inline list-none p-0 m-0 flex gap-2">
@@ -207,11 +255,11 @@ pub fn VideoMetadataForm(
207255
</div>
208256
<div>
209257
<label for="people">"People: "</label>
210-
<Input r#type=InputType::Text id="people" name="data[people]" />
258+
<Input r#type=InputType::Text id="people" name="data[people_manual]" />
211259
</div>
212260
<div>
213261
<label for="tags">"Tags: "</label>
214-
<Input r#type=InputType::Text id="tags" name="data[tags]" />
262+
<Input r#type=InputType::Text id="tags" name="data[tags_manual]" />
215263
</div>
216264
<div class="usable">
217265
//<fieldset>
@@ -240,6 +288,8 @@ pub fn VideoMetadataForm(
240288
</div>
241289
<div>
242290
<input type="hidden" name="data[file]" value=file />
291+
<input type="hidden" name="data[tags]" value=move || selected_tags.get().join(",") />
292+
<input type="hidden" name="data[people]" value=move || selected_people.get().join(",") />
243293
<Button r#type="Submit" >"Submit"</Button>
244294
</div>
245295
</ActionForm>

src/lib_models.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub struct MediaReviewForm {
8989
pub description: String,
9090
pub people: String,
9191
pub tags: String,
92+
pub tags_manual: String,
93+
pub people_manual: String,
9294
pub usable: Option<bool>,
9395
pub highlight: Option<bool>,
9496
}

0 commit comments

Comments
 (0)