Skip to content

Commit

Permalink
feat: save / load
Browse files Browse the repository at this point in the history
  • Loading branch information
freedmand committed Nov 1, 2022
1 parent 406d616 commit 5e23433
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ label * {
pointer-events: none;
}

.button-tweak {
margin-top: -6px;
}

.hidden {
display: none;
}
Expand Down
51 changes: 41 additions & 10 deletions src/components/MatchingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,55 @@ export function MatchingTable({
Redo
</Button>

{/* <Button
<Button
slim={true}
// onClick={() => redo()}
onClick={() => {
download("crosswalk_savepoint.json", app);
}}
>
Save
</Button>
<Button
slim={true}
// onClick={() => redo()}
>
Load
</Button> */}
<input
type="file"
id="file-load-button-upload"
className="hidden"
onInput={(e) =>
(async () => {
let loaded = false;
const target = e.target as HTMLInputElement;
const files = Array.from(target.files || []);

if (files.length === 1) {
const rawContents = await files[0].text();
const json = JSON.parse(rawContents) as MatchingState;

if (json.type === "MatchingState") {
reducer({
type: "LoadState",
state: json,
});
loaded = true;
}
}

// Clear the file input
target.value = "";

if (!loaded) {
alert("Improper file specified");
}
})()
}
/>
<label htmlFor="file-load-button-upload" className="button-tweak">
<Button slim={true}>Load</Button>
</label>

<Button
slim={true}
icon={{
url: downloadIcon,
alt: "Download",
alt: "Export",
}}
onClick={() => {
const getRow = (
Expand Down Expand Up @@ -295,7 +326,7 @@ export function MatchingTable({
download("crosswalk.json", results);
}}
>
Download matches ({allUserMatches.length.toLocaleString()})
Export matches ({allUserMatches.length.toLocaleString()})
</Button>
</div>
</Header>
Expand Down
10 changes: 9 additions & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export type Action =
| UpdateProgress
| FinishProcessing
| ToggleUserMatches
| Reset;
| Reset
| LoadState;

export interface AddTablesFromFiles {
type: "AddTablesFromFiles";
Expand Down Expand Up @@ -187,6 +188,11 @@ export interface Reset {
type: "Reset";
}

export interface LoadState {
type: "LoadState";
state: MatchingState;
}

export const defaultState: State = {
type: "WelcomeState",
};
Expand Down Expand Up @@ -433,6 +439,8 @@ export function appReducer(state: State, action: Action): State {
}
case "Reset":
return defaultState;
case "LoadState":
return action.state;
}
}

Expand Down

1 comment on commit 5e23433

@vercel
Copy link

@vercel vercel bot commented on 5e23433 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

crosswalker – ./

crosswalker.vercel.app
crosswalker-elex.vercel.app
crosswalker-git-main-elex.vercel.app

Please sign in to comment.