This commit is contained in:
Matthew Ryan Dillon 2021-12-08 21:16:33 -07:00
parent 725381c07c
commit d8ff878491
4 changed files with 29 additions and 30 deletions

View file

@ -14,33 +14,32 @@ impl Component for App {
fn view(&self, _ctx: &Context<Self>) -> Html {
html! {
<>
<h1>
<a href="/">{"gpx.thermokar.st"}</a>
</h1>
<>
<h1>
<a href="/">{"gpx.thermokar.st"}</a>
</h1>
<p>
{"This client-side tool is for merging "}
<a href="https://www.topografix.com/gpx.asp">{"GPX files"}</a>
{". Please note, this has only been tested on GPX files produced by "}
<a href="https://www.garmin.com">{"Garmin"}</a>
{" and "}
<a href="https://www.strava.com">{"Strava"}</a>
{" - your mileage may vary."}
</p>
<p>
{"This client-side tool is for merging "}
<a href="https://www.topografix.com/gpx.asp">{"GPX files"}</a>
{". "}
</p>
<Loader />
<Loader />
<hr/>
<hr/>
<p>
<small>
<a href="https://github.com/thermokarst/gpx-web-utils">
{"https://github.com/thermokarst/gpx-web-utils"}
</a>
</small>
</p>
</>
<p>
<small>{"source (public access): git://pingo.thermokar.st/gpx-web-utils"}</small>
<small>
{"Please note, this has only been tested on GPX files produced by "}
<a href="https://www.garmin.com">{"Garmin"}</a>
{" and "}
<a href="https://www.strava.com">{"Strava"}</a>
{" - your mileage may vary."}
</small>
</p>
</>
}
}
}

View file

@ -2,7 +2,7 @@ use std::error::Error;
use wasm_bindgen::prelude::*;
use web_sys::Blob;
fn join_gpx_files(files: &Vec<String>) -> Result<gpx::Gpx, Box<dyn Error>> {
fn join_gpx_files(files: &[String]) -> Result<gpx::Gpx, Box<dyn Error>> {
let mut merged_gpx: gpx::Gpx = Default::default();
let mut merged_track: gpx::Track = gpx::Track::new();
@ -51,7 +51,7 @@ fn write_gpx_to_buffer(gpx: gpx::Gpx) -> Result<js_sys::Array, Box<dyn Error>> {
Ok(array)
}
pub fn merge(files: &Vec<String>) -> Result<Blob, Box<dyn Error>> {
pub fn merge(files: &[String]) -> Result<Blob, Box<dyn Error>> {
let merged: gpx::Gpx = join_gpx_files(files)?;
let out_vec = write_gpx_to_buffer(merged)?;
let result = Blob::new_with_u8_array_sequence(&out_vec).map_err(|e| e.as_string().unwrap())?;

View file

@ -5,7 +5,7 @@ use gloo_file::File;
use web_sys::{Event, HtmlInputElement, Url, MouseEvent};
use yew::{html, html::TargetCast, Component, Context, Html};
use super::utils;
use super::gpx;
pub enum Msg {
FileLoaded(String, String),
@ -52,7 +52,7 @@ impl Component for Loader {
Msg::StartLoad(files) => {
self.count = files.len();
if self.count < 2 {
utils::alert("must load two or more files");
gpx::alert("must load two or more files");
ctx.link().send_message(Msg::Reset);
return true;
}
@ -78,10 +78,10 @@ impl Component for Loader {
}
Msg::FilesLoaded => {
let merged = match utils::merge(&self.files) {
let merged = match gpx::merge(&self.files) {
Ok(result) => result,
Err(err) => {
utils::alert(&err.to_string());
gpx::alert(&err.to_string());
ctx.link().send_message(Msg::Reset);
return true
}

View file

@ -2,7 +2,7 @@ extern crate wee_alloc;
mod app;
mod loader;
mod utils;
mod gpx;
// Use `wee_alloc` as the global allocator.
#[global_allocator]