2020-03-31 22:05:18 +02:00
|
|
|
use seed::fetch::{FetchObject, ResponseWithDataResult};
|
2020-03-31 23:49:46 +02:00
|
|
|
use seed::*;
|
2020-03-31 22:05:18 +02:00
|
|
|
|
2020-04-02 16:14:07 +02:00
|
|
|
use jirs_data::{FullIssue, FullProject, Issue};
|
2020-03-31 22:05:18 +02:00
|
|
|
|
|
|
|
use crate::model::Model;
|
|
|
|
|
|
|
|
pub fn current_user_response(fetched: &FetchObject<String>, model: &mut Model) {
|
|
|
|
if let FetchObject {
|
|
|
|
result:
|
|
|
|
Ok(ResponseWithDataResult {
|
|
|
|
data: Ok(body),
|
|
|
|
status,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
} = fetched
|
|
|
|
{
|
|
|
|
if status.is_error() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
match serde_json::from_str::<'_, jirs_data::User>(body.as_str()) {
|
|
|
|
Ok(user) => {
|
|
|
|
model.user = Some(user);
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn current_project_response(fetched: &FetchObject<String>, model: &mut Model) {
|
|
|
|
if let FetchObject {
|
|
|
|
result:
|
|
|
|
Ok(ResponseWithDataResult {
|
|
|
|
data: Ok(body),
|
|
|
|
status,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
} = fetched
|
|
|
|
{
|
|
|
|
if status.is_error() {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-02 16:14:07 +02:00
|
|
|
match serde_json::from_str::<'_, FullProject>(body.as_str()) {
|
|
|
|
Ok(project) => {
|
|
|
|
model.project = Some(project);
|
2020-03-31 22:05:18 +02:00
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_issue_response(fetched: &FetchObject<String>, model: &mut Model) {
|
|
|
|
if let FetchObject {
|
|
|
|
result:
|
|
|
|
Ok(ResponseWithDataResult {
|
|
|
|
data: Ok(body),
|
|
|
|
status,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
..
|
|
|
|
} = fetched
|
|
|
|
{
|
|
|
|
if status.is_error() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
match (
|
2020-04-02 16:14:07 +02:00
|
|
|
serde_json::from_str::<'_, FullIssue>(body.as_str()),
|
2020-03-31 22:05:18 +02:00
|
|
|
model.project.as_mut(),
|
|
|
|
) {
|
|
|
|
(Ok(issue), Some(project)) => {
|
|
|
|
let mut issues: Vec<Issue> = vec![];
|
2020-04-02 16:14:07 +02:00
|
|
|
std::mem::swap(&mut project.issues, &mut issues);
|
|
|
|
for i in issues.into_iter() {
|
2020-03-31 22:05:18 +02:00
|
|
|
if i.id != issue.id {
|
2020-04-02 16:14:07 +02:00
|
|
|
project.issues.push(i);
|
2020-03-31 22:05:18 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-02 16:14:07 +02:00
|
|
|
project.issues.push(issue.into());
|
|
|
|
}
|
|
|
|
(Err(error), _) => {
|
|
|
|
error!(error);
|
2020-03-31 22:05:18 +02:00
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|