Skip to content

Commit 3b64b52

Browse files
committed
Refactor tag and people handling to improve validation.
Reworked tag and people concatenation to properly filter out empty values before processing. This ensures cleaner input and avoids unnecessary API calls for empty fields. Added a fallback to handle cases with no tags or people provided.
1 parent 8bea442 commit 3b64b52

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/components/metadata_form.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,42 @@ async fn handle_form(data: MediaReviewForm) -> Result<(), ServerFnError> {
7575
log!("File within handle_form: {:?}", data.file);
7676
log!("Handling form");
7777
//combine tags and manual tags
78-
let all_tags = data.tags + "," + &*data.tags_manual;
79-
let tag_ids = match handle_tags(all_tags).await {
80-
Ok(tag_ids) => tag_ids,
81-
Err(e) => {
82-
log!("Error handling tags: {:?}", e);
83-
return Err(e);
78+
let all_tags = [&data.tags, &data.tags_manual]
79+
.iter()
80+
.filter(|s| !s.is_empty())
81+
.map(|s| s.as_str())
82+
.collect::<Vec<_>>()
83+
.join(",");
84+
85+
let tag_ids = if !all_tags.is_empty() {
86+
match handle_tags(all_tags).await {
87+
Ok(tag_ids) => tag_ids,
88+
Err(e) => {
89+
log!("Error handling tags: {:?}", e);
90+
return Err(e);
91+
}
8492
}
93+
} else {
94+
Vec::new()
8595
};
8696
log!("Tag ids: {:?}", tag_ids);
87-
let all_people = data.people + "," + &*data.people_manual;
88-
let person_ids = match handle_people(all_people).await {
89-
Ok(person_ids) => person_ids,
90-
Err(e) => {
91-
log!("Error handling people: {:?}", e);
92-
return Err(e);
97+
let all_people = [&data.people, &data.people_manual]
98+
.iter()
99+
.filter(|s| !s.is_empty())
100+
.map(|s| s.as_str())
101+
.collect::<Vec<_>>()
102+
.join(",");
103+
104+
let person_ids = if !all_people.is_empty() {
105+
match handle_people(all_people).await {
106+
Ok(person_ids) => person_ids,
107+
Err(e) => {
108+
log!("Error handling people: {:?}", e);
109+
return Err(e);
110+
}
93111
}
112+
} else {
113+
Vec::new() // or default empty Vec/appropriate fallback
94114
};
95115
let media_update = MediaUpdate {
96116
file_name: data.file,

0 commit comments

Comments
 (0)