Browse Source

feat: load totals immediately, and prompt to verify giving amount

pull/11/head
Trent Larson 2 years ago
parent
commit
d5abfb0265
  1. 51
      src/views/ContactsView.vue

51
src/views/ContactsView.vue

@ -67,22 +67,8 @@
</button> </button>
</div> </div>
<!-- eslint-disable-next-line --> <div class="flex justify-between" v-if="showGiveTotals">
<div <div class="w-full text-right">
class="flex justify-between"
>
<!-- eslint-disable-next-line -->
<div class="w-1/2 text-left">
<button
href=""
class="left text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-6"
v-if="showGiveTotals"
@click="loadGives()"
>
Load Totals
</button>
</div>
<div class="w-1/2 text-right">
Hours to Add: Hours to Add:
<input <input
class="border border rounded border-slate-400 w-24 text-right" class="border border rounded border-slate-400 w-24 text-right"
@ -133,6 +119,7 @@
<script lang="ts"> <script lang="ts">
import { AxiosError } from "axios"; import { AxiosError } from "axios";
import * as didJwt from "did-jwt"; import * as didJwt from "did-jwt";
import * as R from "ramda";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { AppString } from "@/constants/app"; import { AppString } from "@/constants/app";
@ -153,7 +140,7 @@ export interface GiveVerifiableCredential {
components: {}, components: {},
}) })
export default class ContactsView extends Vue { export default class ContactsView extends Vue {
contacts: Contact[] = []; contacts: Array<Contact> = [];
contactInput = ""; contactInput = "";
// { "did:...": amount } entry for each contact // { "did:...": amount } entry for each contact
givenByMeTotals = {}; givenByMeTotals = {};
@ -167,13 +154,15 @@ export default class ContactsView extends Vue {
// 'created' hook runs when the Vue instance is first created // 'created' hook runs when the Vue instance is first created
async created() { async created() {
await db.open(); await db.open();
const accounts = await db.accounts.toArray();
this.identity = JSON.parse(accounts[0].identity);
this.contacts = await db.contacts.toArray(); this.contacts = await db.contacts.toArray();
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
this.showGiveTotals = params.get("showGiveTotals") == "true"; this.showGiveTotals = params.get("showGiveTotals") == "true";
if (this.showGiveTotals) {
const accounts = await db.accounts.toArray(); this.loadGives();
this.identity = JSON.parse(accounts[0].identity); }
} }
async onClickNewContact(): void { async onClickNewContact(): void {
@ -259,6 +248,10 @@ export default class ContactsView extends Vue {
return !isNaN(str) && !isNaN(parseFloat(str)); return !isNaN(str) && !isNaN(parseFloat(str));
} }
private contactForDid(contacts: Array<Contact>, did: string): Contact {
return R.find((con) => con.did == did, contacts);
}
async onClickAddGive(fromDid: string, toDid: string): void { async onClickAddGive(fromDid: string, toDid: string): void {
if (!this.hourInput) { if (!this.hourInput) {
this.errorMessage = "Giving 0 hours does nothing."; this.errorMessage = "Giving 0 hours does nothing.";
@ -267,7 +260,23 @@ export default class ContactsView extends Vue {
"This is not a valid number of hours: " + this.hourInput; "This is not a valid number of hours: " + this.hourInput;
} else { } else {
this.errorMessage = ""; this.errorMessage = "";
this.createAndSubmitGive(fromDid, toDid, parseFloat(this.hourInput)); let toFrom;
if (fromDid == this.identity.did) {
toFrom = "to " + this.contactForDid(this.contacts, toDid).name;
} else {
toFrom = "from " + this.contactForDid(this.contacts, fromDid).name;
}
if (
confirm(
"Are you sure you want to record " +
this.hourInput +
" hours " +
toFrom +
"?"
)
) {
this.createAndSubmitGive(fromDid, toDid, parseFloat(this.hourInput));
}
} }
} }

Loading…
Cancel
Save