feat: adds github action workflow
This commit is contained in:
parent
c6be33a216
commit
965af89a3b
44
.github/workflows/prod.yml
vendored
Normal file
44
.github/workflows/prod.yml
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo
|
||||||
|
target/
|
||||||
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: ${{ runner.os }}-cargo-
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Build and test code
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
cargo test --verbose
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: shuttle-hq/deploy-action@main
|
||||||
|
with:
|
||||||
|
deploy-key: ${{ secrets.SHUTTLE_API_KEY }}
|
@ -1,5 +1,5 @@
|
|||||||
use gloo_net::http::Request;
|
|
||||||
use gloo_console::log;
|
use gloo_console::log;
|
||||||
|
use gloo_net::http::Request;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use web_sys::wasm_bindgen::convert::OptionIntoWasmAbi;
|
use web_sys::wasm_bindgen::convert::OptionIntoWasmAbi;
|
||||||
use web_sys::wasm_bindgen::JsCast;
|
use web_sys::wasm_bindgen::JsCast;
|
||||||
@ -15,7 +15,11 @@ static NEW_WORD_URI: &str = "https://wordl.shuttleapp.rs/word";
|
|||||||
fn set_focus(index: usize) {
|
fn set_focus(index: usize) {
|
||||||
if let Some(w) = web_sys::window() {
|
if let Some(w) = web_sys::window() {
|
||||||
if let Some(d) = w.document() {
|
if let Some(d) = w.document() {
|
||||||
if let Some(n) = d.query_selector(&format!("[tabindex='{index}']")).ok().flatten() {
|
if let Some(n) = d
|
||||||
|
.query_selector(&format!("[tabindex='{index}']"))
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
{
|
||||||
if let Some(e) = n.dyn_ref::<HtmlElement>() {
|
if let Some(e) = n.dyn_ref::<HtmlElement>() {
|
||||||
e.focus().ok();
|
e.focus().ok();
|
||||||
}
|
}
|
||||||
@ -112,10 +116,10 @@ fn get_word(handle: UseStateHandle<String>) {
|
|||||||
let data = format!("{j:?}");
|
let data = format!("{j:?}");
|
||||||
log!(&data);
|
log!(&data);
|
||||||
handle.set(data);
|
handle.set(data);
|
||||||
},
|
}
|
||||||
None => log!("no body"),
|
None => log!("no body"),
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(e) => log!(format!("FETCH: {e:?}")),
|
Err(e) => log!(format!("FETCH: {e:?}")),
|
||||||
}
|
}
|
||||||
// let res: Word = Request::get(NEW_WORD_URI).send().await.unwrap().json().await.unwrap();
|
// let res: Word = Request::get(NEW_WORD_URI).send().await.unwrap().json().await.unwrap();
|
||||||
@ -134,7 +138,6 @@ fn get_word(handle: UseStateHandle<String>) {
|
|||||||
|
|
||||||
#[function_component]
|
#[function_component]
|
||||||
pub fn Home() -> Html {
|
pub fn Home() -> Html {
|
||||||
|
|
||||||
// let got_word = "HALLO";
|
// let got_word = "HALLO";
|
||||||
// let length = got_word.len();
|
// let length = got_word.len();
|
||||||
log!("STARTING");
|
log!("STARTING");
|
||||||
@ -143,7 +146,6 @@ pub fn Home() -> Html {
|
|||||||
|
|
||||||
// get_word(word.clone());
|
// get_word(word.clone());
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let handle = word.clone();
|
let handle = word.clone();
|
||||||
use_effect_with((), move |()| {
|
use_effect_with((), move |()| {
|
||||||
@ -153,17 +155,29 @@ pub fn Home() -> Html {
|
|||||||
let res = Request::get(NEW_WORD_URI).send().await;
|
let res = Request::get(NEW_WORD_URI).send().await;
|
||||||
log!(format!("RESPONSE: {res:?}"));
|
log!(format!("RESPONSE: {res:?}"));
|
||||||
match res {
|
match res {
|
||||||
|
// Ok(r) => {
|
||||||
|
// log!(format!("{r:?}"));
|
||||||
|
// match r.json::<Word>().await {
|
||||||
|
// Ok(j) => {
|
||||||
|
// let data = format!("{j:?}");
|
||||||
|
// log!(&data);
|
||||||
|
// handle.set(data);
|
||||||
|
// },
|
||||||
|
// Err(e) => log!(format!("{e:?}")),
|
||||||
|
// }
|
||||||
|
// },
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
log!(format!("{r:?}"));
|
log!(format!("{r:?}"));
|
||||||
match r.json::<Word>().await {
|
match r.body() {
|
||||||
Ok(j) => {
|
Some(j) => {
|
||||||
|
let j = j.to_string();
|
||||||
let data = format!("{j:?}");
|
let data = format!("{j:?}");
|
||||||
log!(&data);
|
log!(&data);
|
||||||
handle.set(data);
|
handle.set(data);
|
||||||
},
|
|
||||||
Err(e) => log!(format!("{e:?}")),
|
|
||||||
}
|
}
|
||||||
},
|
None => log!("no body"),
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(e) => log!(format!("FETCH: {e:?}")),
|
Err(e) => log!(format!("FETCH: {e:?}")),
|
||||||
}
|
}
|
||||||
// let res: Word = Request::get(NEW_WORD_URI).send().await.unwrap().json().await.unwrap();
|
// let res: Word = Request::get(NEW_WORD_URI).send().await.unwrap().json().await.unwrap();
|
||||||
@ -181,7 +195,8 @@ pub fn Home() -> Html {
|
|||||||
}
|
}
|
||||||
let length = word.len();
|
let length = word.len();
|
||||||
|
|
||||||
let submitted_words: UseStateHandle<Vec<Vec<CharStatus<String>>>> = use_state(|| std::vec::Vec::with_capacity(length));
|
let submitted_words: UseStateHandle<Vec<Vec<CharStatus<String>>>> =
|
||||||
|
use_state(|| std::vec::Vec::with_capacity(length));
|
||||||
|
|
||||||
let node_refs = use_state(|| vec![NodeRef::default(); length]);
|
let node_refs = use_state(|| vec![NodeRef::default(); length]);
|
||||||
let input_values: UseStateHandle<Vec<String>> = use_state(|| vec![String::new(); length]);
|
let input_values: UseStateHandle<Vec<String>> = use_state(|| vec![String::new(); length]);
|
||||||
@ -192,7 +207,11 @@ pub fn Home() -> Html {
|
|||||||
let iv = input_values.clone();
|
let iv = input_values.clone();
|
||||||
let game_over = game_over.clone();
|
let game_over = game_over.clone();
|
||||||
Callback::from(move |_| {
|
Callback::from(move |_| {
|
||||||
if submitted_words.iter().count() >= length - 1 || crate::compare_strings(&word, &iv.join("")).iter().all(|v| matches!(v, CharStatus::Match(_))){
|
if submitted_words.iter().count() >= length - 1
|
||||||
|
|| crate::compare_strings(&word, &iv.join(""))
|
||||||
|
.iter()
|
||||||
|
.all(|v| matches!(v, CharStatus::Match(_)))
|
||||||
|
{
|
||||||
game_over.set(true);
|
game_over.set(true);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user