FINAL BEFORE SUBMITION :(

This commit is contained in:
LinlyBoi
2022-12-26 01:03:42 +02:00
parent c93bb7ad17
commit 94686d5815
7 changed files with 37 additions and 25 deletions

View File

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