Considerable cleanup and merge

This commit is contained in:
Matthew Raymer
2023-07-06 16:59:50 +08:00
parent f568149745
commit 3b41014083
8 changed files with 196 additions and 130 deletions

View File

@@ -146,7 +146,6 @@
<script lang="ts">
import { AxiosError } from "axios";
import * as moment from "moment";
import * as R from "ramda";
import { Component, Vue } from "vue-facing-decorator";
import GiftedDialog from "@/components/GiftedDialog.vue";
@@ -174,6 +173,8 @@ export default class ProjectViewView extends Vue {
timeSince = "";
projectId = localStorage.getItem("projectId") || ""; // handle ID
errorMessage = "";
alertMessage = "";
alertTitle = "";
onEditClick() {
localStorage.setItem("projectId", this.projectId as string);
@@ -210,6 +211,7 @@ export default class ProjectViewView extends Vue {
const eventDate = new Date(startTime);
const now = moment.now();
this.timeSince = moment.utc(now).to(eventDate);
errorMessage;
}
this.name = resp.data.claim?.name || "(no name)";
this.description = resp.data.claim?.description || "(no description)";
@@ -231,7 +233,6 @@ export default class ProjectViewView extends Vue {
}
}
// 'created' hook runs when the Vue instance is first created
async created() {
await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
@@ -245,10 +246,12 @@ export default class ProjectViewView extends Vue {
console.error("Problem! Should have a profile!");
} else {
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === this.activeDid, accounts);
const account = accounts.find((acc) => acc.did === this.activeDid);
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error("No identity found.");
throw new Error(
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service."
);
}
this.LoadProject(identity);
}
@@ -257,6 +260,7 @@ export default class ProjectViewView extends Vue {
openDialog(contact) {
this.$refs.customDialog.open(contact);
}
handleDialogResult(result) {
if (result.action === "confirm") {
return new Promise((resolve) => {
@@ -275,60 +279,60 @@ export default class ProjectViewView extends Vue {
* @param hours may be 0
*/
async recordGive(giverDid, description, hours) {
if (this.activeDid == null) {
if (!this.activeDid) {
this.alertTitle = "Error";
this.alertMessage =
"You must select an identity before you can record a give.";
return;
}
if (!description && !hours) {
this.alertTitle = "Error";
this.alertMessage =
"You must enter a description or some number of hours.";
return;
}
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === this.activeDid, accounts);
const account = accounts.find((acc) => acc.did === this.activeDid);
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error("No identity found.");
throw new Error(
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service."
);
}
createAndSubmitGive(
this.axios,
this.apiServer,
identity,
giverDid,
this.activeDid,
description,
hours,
this.projectId
)
.then((result) => {
if (result.status != 201 || result.data?.error) {
console.log("Error with give result:", result);
this.alertTitle = "Error";
this.alertMessage =
result.data?.error?.message ||
"There was an error recording the give.";
} else {
this.alertTitle = "Success";
this.alertMessage = "That gift was recorded.";
//this.updateAllFeed(); // full update is overkill but we should show something
}
})
.catch((e) => {
// axios throws errors on 400 responses
console.log("Error with give caught:", e);
try {
const result = await createAndSubmitGive(
this.axios,
this.apiServer,
identity,
giverDid,
this.activeDid,
description,
hours,
this.projectId
);
if (result.status !== 201 || result.data?.error) {
console.log("Error with give result:", result);
this.alertTitle = "Error";
this.alertMessage =
e.userMessage ||
e.response?.data?.error?.message ||
result.data?.error?.message ||
"There was an error recording the give.";
});
} else {
this.alertTitle = "Success";
this.alertMessage = "That gift was recorded.";
}
} catch (e) {
console.log("Error with give caught:", e);
this.alertTitle = "Error";
this.alertMessage =
e.userMessage ||
e.response?.data?.error?.message ||
"There was an error recording the give.";
}
}
// This same popup code is in many files.
alertMessage = "";
alertTitle = "";
}
</script>