diff --git a/.github/workflows/deploy-to-pages.yml b/.github/workflows/deploy-to-pages.yml new file mode 100644 index 0000000..0b923e2 --- /dev/null +++ b/.github/workflows/deploy-to-pages.yml @@ -0,0 +1,51 @@ +name: Deploy to Pages + +on: + # Runs on pushes targeting the default branch + # push: + # branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Install Trunk + uses: jetli/trunk-action@v0.5.0 + - name: Build + run: trunk build --release --no-default-features + working-directory: client + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: client/dist + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/client/Cargo.toml b/client/Cargo.toml index 10f6bd8..1957429 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -21,5 +21,9 @@ web-sys = { version = "0.3.72", features = [ "TextMetrics", ] } +[features] +default = ["online"] +online = [] + [lints] workspace = true diff --git a/client/src/dialog.rs b/client/src/dialog.rs index a3672ef..946f831 100644 --- a/client/src/dialog.rs +++ b/client/src/dialog.rs @@ -117,7 +117,10 @@ impl DialogImpl for MainMenuDialog {
"Main Menu"
} } diff --git a/client/src/lib.rs b/client/src/lib.rs index 2cec66f..189e556 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -6,7 +6,7 @@ mod game_view; use base64::{prelude::BASE64_STANDARD, Engine}; use c6ol_core::{ game::{Move, Point, Record, Stone}, - protocol::{ClientMessage, GameId, Request, ServerMessage}, + protocol::{ClientMessage, Request, ServerMessage}, }; use dialog::*; use leptos::{ev, prelude::*}; @@ -348,16 +348,17 @@ pub fn App() -> impl IntoView { return; } - if let Some(id) = GameId::try_from(id.as_bytes()) - .ok() - .filter(|id| id.iter().all(u8::is_ascii_alphanumeric)) - { - connect(ClientMessage::Join(id)); - } else { - show_dialog(Dialog::from(ErrorDialog { - message: "Invalid game ID.".into(), - })); + #[cfg(feature = "online")] + if let Ok(id) = c6ol_core::protocol::GameId::try_from(id.as_bytes()) { + if id.iter().all(u8::is_ascii_alphanumeric) { + connect(ClientMessage::Join(id)); + return; + } } + + show_dialog(Dialog::from(ErrorDialog { + message: "Invalid game ID.".into(), + })); }; let on_event = move |ev: Event| match ev {