diff --git a/src/components/checkbox.rs b/src/components/checkbox.rs index 1030757..47e5791 100644 --- a/src/components/checkbox.rs +++ b/src/components/checkbox.rs @@ -77,29 +77,28 @@ pub fn CheckboxList( move || { let result = ValueType::String(Some(item_name.clone())); data_map.update(|map| { - if let Some(value_type) = map.get_mut(&data_member) { - // Get the list from the enum - if let Some(mut list) = value_type.as_list().unwrap_or(None) { - // Check if the value exists in the list or not. Both of these branches - // directly update the value within the hash map, otherwise the change - // isn't reactive. - if let Some(index) = list.iter().position(|val| *val == result) { - // Value is already selected, deselect it. - list.remove(index); - } else { - // Value is not selected, so select it. - list.push(result); - } - *value_type = ValueType::List(Some(list)); - } else { - // Update the value at the current data_member - let temp = map.get_mut(&data_member.clone()).unwrap(); - *temp = ValueType::List(Some(vec![result])); - } - } else { - // Insert a new list into the hash map - map.insert(data_member.clone(), ValueType::List(Some(vec![result]))); - } + // Attempt to get the value type from the hash map. + match map.get_mut(&data_member) { + Some(value_type) => { + // Attempt to get the value as a list. + match value_type.as_list().unwrap_or(None) { + Some(mut list) => { + // Attempt to find the selected value in the selected list. + // If it's present, remove it, or vice versa. + match list.iter().position(|val| *val == result) { + Some(index) => { list.remove(index); }, + None => { list.push(result); } + }; + // Update the existing value_type entry in the hash map. + *value_type = ValueType::List(Some(list)); + }, + // Insert a new value_type entry. + None => { *value_type = ValueType::List(Some(vec![result])); } + }; + }, + // Insert a new value_type entry. + None => { map.insert(data_member.clone(), ValueType::List(Some(vec![result]))); } + }; }); } }; diff --git a/src/pages/home_page.rs b/src/pages/home_page.rs index 6dc6cb7..ec862d7 100644 --- a/src/pages/home_page.rs +++ b/src/pages/home_page.rs @@ -25,7 +25,7 @@ pub async fn get_submission(id: String) -> Result { let dbclient = Client::new(&config); console_log(format!("Getting values from API using username {}", id).as_str()); - + // Gets the item from the database. It only returns an error if the database // experiences an error - not if the item is not found. match dbclient @@ -58,7 +58,7 @@ pub async fn get_submission(id: String) -> Result { /// /// All information is stored using a `PutItemCommand` in the student application DynamoDB table. #[server(CreateSampleSubmission, endpoint = "/create-sample-submission")] -pub async fn create_sample_submission(student_info: StudentInfo) -> Result<(), ServerFnError> { +pub async fn create_sample_submission(student_info: ExpandableInfo) -> Result<(), ServerFnError> { let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await; let dbclient = Client::new(&config); @@ -137,7 +137,6 @@ pub fn HomePage() -> impl IntoView { server_resource .get() .map(|submission| { - let store_info = Store::new(submission.clone()); let expandable = ExpandableInfo::new("email".into()); let expandable_react = expandable.as_reactive(); expandable_react.data.update(|map| { @@ -145,7 +144,6 @@ pub fn HomePage() -> impl IntoView { map.insert("phone_number".into(), ValueType::String(Some("123456789-10".into()))); map.insert("math_sat".into(), ValueType::Number(Some(1234))); }); - let reactive_info = submission.as_reactive(); let elements_disabled = RwSignal::new(false); let result_msg = Signal::derive(move || { // Eventually, this function will show and hide a loading symbol @@ -275,18 +273,12 @@ pub fn HomePage() -> impl IntoView { "Submit"