Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Govt-Billing-React/src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,22 @@ const Menu: React.FC<{
printWindow.print();
}
};
const doSave = () => {
const doSave = async () => {
if (props.file === "default") {
setShowAlert1(true);
return;
}
const content = encodeURIComponent(AppGeneral.getSpreadsheetContent());
const data = props.store._getFile(props.file);
const data = await props.store._getFile(props.file);

if (!data) {
setToastMessage("Save failed: file data could not be retrieved.");
setShowToast1(true);
return;
}

const file = new File(
(data as any).created,
data.created,
new Date().toString(),
content,
props.file,
Expand Down
26 changes: 22 additions & 4 deletions Govt-Billing-React/src/components/NewFile/NewFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from "react";
import * as AppGeneral from "../socialcalc/index.js";
import { File, Local } from "../Storage/LocalStorage";
import { DATA } from "../../app-data.js";
import { IonAlert, IonIcon } from "@ionic/react";
import { IonAlert, IonIcon, IonToast } from "@ionic/react";
import { add } from "ionicons/icons";

const NewFile: React.FC<{
Expand All @@ -12,12 +12,22 @@ const NewFile: React.FC<{
billType: number;
}> = (props) => {
const [showAlertNewFileCreated, setShowAlertNewFileCreated] = useState(false);
const newFile = () => {
const [showToast, setShowToast] = useState(false);
const [toastMessage, setToastMessage] = useState("");

const newFile = async () => {
if (props.file !== "default") {
const content = encodeURIComponent(AppGeneral.getSpreadsheetContent());
const data = props.store._getFile(props.file);
const data = await props.store._getFile(props.file);

if (!data) {
setToastMessage("Could not persist current file before reset.");
setShowToast(true);
return;
}

const file = new File(
(data as any).created,
data.created,
new Date().toString(),
content,
props.file,
Expand Down Expand Up @@ -52,6 +62,14 @@ const NewFile: React.FC<{
message={"New file created!"}
buttons={["Ok"]}
/>
<IonToast
animated
isOpen={showToast}
onDidDismiss={() => setShowToast(false)}
position="bottom"
message={toastMessage}
duration={1500}
/>
</React.Fragment>
);
};
Expand Down