) => {
+ const file = event.target.files?.[0];
+ if (file) {
+ const reader = new FileReader();
+ reader.onload = (e) => {
+ try {
+ const content = e.target?.result;
+ if (typeof content === "string") {
+ const parsedRoute: Route = JSON.parse(content);
+ dispatch(uploadRoute(parsedRoute));
+ navigate("/uploaded");
+ }
+ } catch (error) {
+ console.error("Failed to parse route:", error);
+ // Handle the error. Maybe update the state to show an error message.
+ }
+ };
+ reader.readAsText(file);
+ }
+ };
return (
@@ -54,6 +79,8 @@ function RouteSelection() {
placeholder="Input remote route URL"
/>
{customRouteUrl && Go}
+
.. Or upload a route file
+
);
}
diff --git a/src/components/RunMosaic/RunMosaic.tsx b/src/components/RunMosaic/RunMosaic.tsx
index e015422..c1be78b 100644
--- a/src/components/RunMosaic/RunMosaic.tsx
+++ b/src/components/RunMosaic/RunMosaic.tsx
@@ -41,7 +41,7 @@ import { useKeyBindings } from "./useKeyBindings";
import { useLivesplit } from "./useLiveSplit";
type RunParams = {
- routeUrl: string;
+ routeUrl?: string;
user?: string;
repo?: string;
path?: string;
diff --git a/src/store/routeSlice.ts b/src/store/routeSlice.ts
index db8c4f6..fc62a02 100644
--- a/src/store/routeSlice.ts
+++ b/src/store/routeSlice.ts
@@ -35,7 +35,12 @@ export const loadRoute = createAsyncThunk) => {
+ state.data = action.payload;
+ state.status = "succeeded";
+ },
+ },
extraReducers: (builder) => {
builder
.addCase(loadRoute.pending, (state) => {
@@ -57,4 +62,6 @@ export const selectRouteStatus = (state: RootState) => state.route.status;
export const selectRouteData = (state: RootState) => state.route.data;
export const selectRouteError = (state: RootState) => state.route.error;
+export const { uploadRoute } = routeSlice.actions;
+
export default routeSlice.reducer;