|
|
|
<template>
|
|
|
|
<QuickNav selected="Home"></QuickNav>
|
|
|
|
<!-- CONTENT -->
|
|
|
|
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
|
|
|
|
<!-- Breadcrumb -->
|
|
|
|
<div id="ViewBreadcrumb" class="mb-8">
|
|
|
|
<h1 class="text-lg text-center font-light relative px-7">
|
|
|
|
<!-- Back -->
|
|
|
|
<fa
|
|
|
|
icon="chevron-left"
|
|
|
|
@click="$router.back()"
|
|
|
|
class="fa-fw text-lg text-center px-2 py-1 absolute -left-2 -top-1"
|
|
|
|
/>
|
|
|
|
New Activity For You
|
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Display a single row with the name of "New Offers To You" with a count. -->
|
|
|
|
<div class="mb-4">
|
|
|
|
<span class="text-lg font-medium">{{ newOffersToUser.length }}</span>
|
|
|
|
<span class="text-lg font-medium ml-4"
|
|
|
|
>New Offer{{ newOffersToUser.length === 1 ? "" : "s" }} To You</span
|
|
|
|
>
|
|
|
|
<fa
|
|
|
|
:icon="showOffersDetails ? 'chevron-down' : 'chevron-right'"
|
|
|
|
class="cursor-pointer ml-4 text-lg"
|
|
|
|
@click="expandOffersToUserAndMarkRead()"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="showOffersDetails" class="ml-4">
|
|
|
|
<ul class="list-disc ml-4">
|
|
|
|
<li v-for="offer in newOffersToUser" :key="offer.id" class="mt-4 relative group">
|
|
|
|
<span>{{
|
|
|
|
didInfo(offer.offeredByDid, activeDid, allMyDids, allContacts)
|
|
|
|
}}</span>
|
|
|
|
offers
|
|
|
|
<span v-if="offer.objectDescription">{{ offer.objectDescription }}</span>
|
|
|
|
<span v-if="offer.amount">{{
|
|
|
|
displayAmount(offer.unit, offer.amount)
|
|
|
|
}}</span>
|
|
|
|
<router-link
|
|
|
|
:to="{ path: '/claim/' + encodeURIComponent(offer.jwtId) }"
|
|
|
|
class="text-blue-500"
|
|
|
|
>
|
|
|
|
<fa icon="file-lines" class="pl-2 text-blue-500 cursor-pointer" />
|
|
|
|
</router-link>
|
|
|
|
<!-- New line that appears on hover -->
|
|
|
|
<div
|
|
|
|
@click="markOffersAsReadStartingWith(offer.jwtId)"
|
|
|
|
class="absolute left-0 w-full text-left text-gray-500 text-sm hidden group-hover:flex cursor-pointer items-center"
|
|
|
|
>
|
|
|
|
<span class="inline-block w-8 h-px bg-gray-500 mr-2" />
|
|
|
|
Click to keep all above as new offers
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Vue } from "vue-facing-decorator";
|
|
|
|
|
|
|
|
import GiftedDialog from "@/components/GiftedDialog.vue";
|
|
|
|
import QuickNav from "@/components/QuickNav.vue";
|
|
|
|
import EntityIcon from "@/components/EntityIcon.vue";
|
|
|
|
import { NotificationIface } from "@/constants/app";
|
|
|
|
import { accountsDB, db, retrieveSettingsForActiveAccount, updateAccountSettings } from "@/db/index";
|
|
|
|
import { Contact } from "@/db/tables/contacts";
|
|
|
|
import {
|
|
|
|
didInfo,
|
|
|
|
displayAmount,
|
|
|
|
getNewOffersToUser,
|
|
|
|
OfferSummaryRecord,
|
|
|
|
} from "@/libs/endorserServer";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: { GiftedDialog, QuickNav, EntityIcon },
|
|
|
|
})
|
|
|
|
export default class NewActivityView extends Vue {
|
|
|
|
$notify!: (notification: NotificationIface, timeout?: number) => void;
|
|
|
|
|
|
|
|
activeDid = "";
|
|
|
|
allContacts: Array<Contact> = [];
|
|
|
|
allMyDids: string[] = [];
|
|
|
|
apiServer = "";
|
|
|
|
lastAckedOfferToUserJwtId = "";
|
|
|
|
newOffersToUser: Array<OfferSummaryRecord> = [];
|
|
|
|
|
|
|
|
showOffersDetails = false;
|
|
|
|
|
|
|
|
didInfo = didInfo;
|
|
|
|
displayAmount = displayAmount;
|
|
|
|
|
|
|
|
async created() {
|
|
|
|
try {
|
|
|
|
const settings = await retrieveSettingsForActiveAccount();
|
|
|
|
this.apiServer = settings.apiServer || "";
|
|
|
|
this.activeDid = settings.activeDid || "";
|
|
|
|
this.lastAckedOfferToUserJwtId = settings.lastAckedOfferToUserJwtId || "";
|
|
|
|
|
|
|
|
this.allContacts = await db.contacts.toArray();
|
|
|
|
|
|
|
|
await accountsDB.open();
|
|
|
|
const allAccounts = await accountsDB.accounts.toArray();
|
|
|
|
if (allAccounts.length > 0) {
|
|
|
|
this.allMyDids = allAccounts.map((acc) => acc.did);
|
|
|
|
}
|
|
|
|
this.newOffersToUser = await getNewOffersToUser(
|
|
|
|
this.axios,
|
|
|
|
this.apiServer,
|
|
|
|
this.activeDid,
|
|
|
|
this.lastAckedOfferToUserJwtId,
|
|
|
|
);
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
} catch (err: any) {
|
|
|
|
console.error("Error retrieving settings & contacts:", err);
|
|
|
|
this.$notify(
|
|
|
|
{
|
|
|
|
group: "alert",
|
|
|
|
type: "danger",
|
|
|
|
title: "Error",
|
|
|
|
text: err.message || "There was an error retrieving your activity.",
|
|
|
|
},
|
|
|
|
5000,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async expandOffersToUserAndMarkRead() {
|
|
|
|
this.showOffersDetails = !this.showOffersDetails;
|
|
|
|
if (this.newOffersToUser.length > 0) {
|
|
|
|
await updateAccountSettings(this.activeDid, {
|
|
|
|
lastAckedOfferToUserJwtId: this.newOffersToUser[0].jwtId,
|
|
|
|
});
|
|
|
|
// note that we don't update this.lastAckedOfferToUserJwtId in case they
|
|
|
|
// later choose the last one to keep the offers as new
|
|
|
|
}
|
|
|
|
this.$notify(
|
|
|
|
{
|
|
|
|
group: "alert",
|
|
|
|
type: "info",
|
|
|
|
title: "Marked as Read",
|
|
|
|
text: "The offers are marked as viewed. Click in the list to keep them as new.",
|
|
|
|
},
|
|
|
|
5000,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async markOffersAsReadStartingWith(jwtId: string) {
|
|
|
|
const index = this.newOffersToUser.findIndex(offer => offer.jwtId === jwtId);
|
|
|
|
if (index !== -1 && index < this.newOffersToUser.length - 1) {
|
|
|
|
// Set to the next offer's jwtId
|
|
|
|
await updateAccountSettings(this.activeDid, {
|
|
|
|
lastAckedOfferToUserJwtId: this.newOffersToUser[index + 1].jwtId,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// it's the last entry (or not found), so just keep it the same
|
|
|
|
await updateAccountSettings(this.activeDid, {
|
|
|
|
lastAckedOfferToUserJwtId: this.lastAckedOfferToUserJwtId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.$notify(
|
|
|
|
{
|
|
|
|
group: "alert",
|
|
|
|
type: "info",
|
|
|
|
title: "Marked as Unread",
|
|
|
|
text: "All offers above that one are marked as unread.",
|
|
|
|
},
|
|
|
|
3000,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|