2 Commits

Author SHA1 Message Date
LinlyBoi
8b6989f45e thank you clippy very cool 2022-12-30 15:11:13 +02:00
LinlyBoi
97822502c4 ??? 2022-12-30 15:09:45 +02:00
2 changed files with 17 additions and 23 deletions

View File

@@ -48,8 +48,8 @@ impl UseAble for CommonAdmin {
//Wwasm bingdengen code //Wwasm bingdengen code
const DRIVER_URL: &str = "http://db.sewelam.tech/api/driver/50"; const DRIVER_URL: &str = "http://db.sewelam.tech/api/driver/50";
const ADMIN_URL: &str = "http://db.sewelam.tech/api/admin/69422"; const ADMIN_URL: &str = "http://db.sewelam.tech/api/admin/";
const TICKET_URL: &str = "http://db.sewelam.tech/api/ticket/32"; const TICKET_URL: &str = "http://db.sewelam.tech/api/ticket/";
const FUNNY_TXT_URL: &str = "https://whatthecommit.com/index.txt"; const FUNNY_TXT_URL: &str = "https://whatthecommit.com/index.txt";
const INCORRECT_URL: &str = "http://libkyy.cf"; const INCORRECT_URL: &str = "http://libkyy.cf";
//Generic Msg for our states //Generic Msg for our states
@@ -58,31 +58,29 @@ pub enum Msg<T> {
GetData, GetData,
GetError, GetError,
} }
pub struct TextRequestComponent { pub struct RandomCommit {
text_request: FetchState<String>, commit: FetchState<String>,
} }
//This trait is for all yew components //This trait is for all yew components
impl Component for TextRequestComponent { impl Component for RandomCommit {
type Message = Msg<String>; type Message = Msg<String>;
type Properties = (); type Properties = ();
fn create(_ctx: &Context<Self>) -> Self { fn create(_ctx: &Context<Self>) -> Self {
Self { Self {
text_request: FetchState::NotFetching, //Default state is not fetching anything commit: FetchState::NotFetching, //Default state is not fetching anything
} }
} }
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool { fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg { match msg {
Msg::SetDataFetchState(fetch_state) => { Msg::SetDataFetchState(fetch_state) => {
self.text_request = fetch_state; self.commit = fetch_state;
true true
} }
Msg::GetData => { Msg::GetData => {
ctx.link().send_future(async { ctx.link().send_future(async {
match fetch_url_text(TICKET_URL).await { match fetch_url_text(FUNNY_TXT_URL).await {
Ok(text_request) => { Ok(commit) => Msg::SetDataFetchState(FetchState::Success(commit)),
Msg::SetDataFetchState(FetchState::Success(text_request))
}
Err(err) => Msg::SetDataFetchState(FetchState::Failed(err)), Err(err) => Msg::SetDataFetchState(FetchState::Failed(err)),
} }
}); });
@@ -92,10 +90,8 @@ impl Component for TextRequestComponent {
} }
Msg::GetError => { Msg::GetError => {
ctx.link().send_future(async { ctx.link().send_future(async {
match fetch_url_text(ADMIN_URL).await { match fetch_url_text(INCORRECT_URL).await {
Ok(text_request) => { Ok(commit) => Msg::SetDataFetchState(FetchState::Success(commit)),
Msg::SetDataFetchState(FetchState::Success(text_request))
}
Err(err) => Msg::SetDataFetchState(FetchState::Failed(err)), Err(err) => Msg::SetDataFetchState(FetchState::Failed(err)),
} }
}); });
@@ -107,14 +103,11 @@ impl Component for TextRequestComponent {
} }
fn view(&self, ctx: &Context<Self>) -> Html { fn view(&self, ctx: &Context<Self>) -> Html {
match &self.text_request { match &self.commit {
FetchState::NotFetching => html! { FetchState::NotFetching => html! {
<> <>
<button onclick={ctx.link().callback(|_| Msg::GetData)}> <button onclick={ctx.link().callback(|_| Msg::GetData)}>
{ "Get Example Ticket" } { "Get commit msg" }
</button>
<button onclick={ctx.link().callback(|_| Msg::GetError)}>
{ "Get Example Admin " }
</button> </button>
</> </>
}, },
@@ -249,3 +242,4 @@ async fn fetch_url_text(url: &'static str) -> Result<String, FetchError> {
} }
//Admin component //Admin component

View File

@@ -1,7 +1,7 @@
use actix_web::{ use actix_web::{
get, get,
http::header::ContentType, http::header::ContentType,
web::{self, Json}, web::{self},
HttpResponse, Responder, HttpResponse, Responder,
}; };
use backend::{ use backend::{
@@ -86,7 +86,7 @@ async fn api_test() -> impl Responder {
#[get("api/vehicle/{id}")] #[get("api/vehicle/{id}")]
async fn api_vehicle(id: web::Path<String>) -> impl Responder { async fn api_vehicle(id: web::Path<String>) -> impl Responder {
let id = id.into_inner(); let id = id.into_inner();
let fetched_vehicle_data = get_vehicle(&mut establish_connection(), String::from(id)); let fetched_vehicle_data = get_vehicle(&mut establish_connection(), id);
HttpResponse::Ok() HttpResponse::Ok()
.content_type(ContentType::plaintext()) .content_type(ContentType::plaintext())
.insert_header(("Access-Control-Allow-Origin", "*")) .insert_header(("Access-Control-Allow-Origin", "*"))