Browse Source

Add AlertMessage component

pull/29/head
Matthew Raymer 1 year ago
parent
commit
c859778832
  1. 58
      src/views/ProjectsView.vue

58
src/views/ProjectsView.vue

@ -107,18 +107,22 @@
</li> </li>
</ul> </ul>
</InfiniteScroll> </InfiniteScroll>
<AlertMessage
:alertTitle="alertTitle"
:alertMessage="alertMessage"
></AlertMessage>
</section> </section>
</template> </template>
<script lang="ts"> <script lang="ts">
import * as R from "ramda"; import * as R from "ramda";
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
import { accountsDB, db } from "@/db"; import { accountsDB, db } from "@/db";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto"; import { accessToken } from "@/libs/crypto";
import { IIdentifier } from "@veramo/core"; import { IIdentifier } from "@veramo/core";
import InfiniteScroll from "@/components/InfiniteScroll"; import InfiniteScroll from "@/components/InfiniteScroll";
import AlertMessage from "@/components/AlertMessage";
/** /**
* Represents data about a project * Represents data about a project
@ -143,13 +147,15 @@ interface ProjectData {
} }
@Component({ @Component({
components: { InfiniteScroll }, components: { InfiniteScroll, AlertMessage },
}) })
export default class ProjectsView extends Vue { export default class ProjectsView extends Vue {
apiServer = ""; apiServer = "";
projects: ProjectData[] = []; projects: ProjectData[] = [];
current: IIdentifier; current: IIdentifier;
isLoading = false; isLoading = false;
alertTitle = "";
alertMessage = "";
/** /**
* Core project data loader * Core project data loader
@ -171,9 +177,13 @@ export default class ProjectsView extends Vue {
const { name, description, handleId = plan.fullIri, rowid } = plan; const { name, description, handleId = plan.fullIri, rowid } = plan;
this.projects.push({ name, description, handleId, rowid }); this.projects.push({ name, description, handleId, rowid });
} }
} else {
console.log(resp.status);
} }
} catch (error) { } catch (error) {
console.error("Got error loading projects:", error); console.error("Got error loading projects:", error.message);
this.alertTitle = "Error";
this.alertMessage = "Got an error loading projects:" + error.message;
} finally { } finally {
this.isLoading = false; this.isLoading = false;
} }
@ -218,24 +228,32 @@ export default class ProjectsView 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(); try {
const settings = await db.settings.get(MASTER_SETTINGS_KEY); await db.open();
const activeDid = settings?.activeDid || ""; const settings = await db.settings.get(MASTER_SETTINGS_KEY);
this.apiServer = settings?.apiServer || ""; const activeDid = settings?.activeDid || "";
this.apiServer = settings?.apiServer || "";
await accountsDB.open();
const num_accounts = await accountsDB.accounts.count(); await accountsDB.open();
if (num_accounts === 0) { const num_accounts = await accountsDB.accounts.count();
console.error("Problem! Should have a profile!"); if (num_accounts === 0) {
} else { console.error("Problem! You need a profile!");
const accounts = await accountsDB.accounts.toArray(); this.alertTitle = "Error!";
const account = R.find((acc) => acc.did === activeDid, accounts); this.alertMessage = "Problem! You need a profile!";
const identity = JSON.parse(account?.identity || "null"); } else {
if (!identity) { const accounts = await accountsDB.accounts.toArray();
throw new Error("No identity found."); const account = R.find((acc) => acc.did === activeDid, accounts);
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error("No identity found.");
}
this.current = identity;
this.LoadProjects(identity);
} }
this.current = identity; } catch (err) {
this.LoadProjects(identity); console.log(err);
this.alertTitle = "Error!";
this.alertMessage = "Problem! You need a profile!";
} }
} }

Loading…
Cancel
Save