-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d329fd8
commit b766d85
Showing
7 changed files
with
183 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,4 +210,3 @@ fn get_key_collections() -> ExternResult<Vec<(EntryHash, Record)>> { | |
|
||
Ok(records) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
use hdi::prelude::*; | ||
|
||
use crate::prelude::GpgKeyDist; | ||
use crate::LinkTypes; | ||
use crate::UnitEntryTypes; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,60 @@ | ||
import { AppAgentClient, Record } from "@holochain/client"; | ||
import { AppAgentClient } from "@holochain/client"; | ||
import { defineStore } from "pinia"; | ||
import { ComputedRef, inject, ref, watch } from "vue"; | ||
import { GpgKeyDist } from "../trusted/trusted/types"; | ||
import { registerSignalHandler } from "../signals"; | ||
|
||
export interface KeyCollectionWithKeys { | ||
name: string; | ||
gpg_keys: GpgKeyDist[]; | ||
name: string; | ||
gpg_keys: GpgKeyDist[]; | ||
} | ||
|
||
export const useKeyCollectionsStore = defineStore("key-collections", () => { | ||
const keyCollections = ref<KeyCollectionWithKeys[]>([]); | ||
|
||
const pushKeyCollection = (collection: KeyCollectionWithKeys) => { | ||
keyCollections.value.push(collection); | ||
}; | ||
|
||
const addKeyToCollection = (name: string, key: GpgKeyDist) => { | ||
const existingCollection = keyCollections.value.find((c) => c.name === name); | ||
if (existingCollection) { | ||
existingCollection.gpg_keys.push(key); | ||
} | ||
}; | ||
|
||
const client = inject("client") as ComputedRef<AppAgentClient>; | ||
const loadKeyCollections = async (client: AppAgentClient) => { | ||
const collections: KeyCollectionWithKeys[] = await client.callZome({ | ||
role_name: "trusted", | ||
zome_name: "trusted", | ||
fn_name: "get_my_key_collections", | ||
payload: null, | ||
cap_secret: null, | ||
}); | ||
|
||
console.log('loaded key collections', collections); | ||
|
||
keyCollections.value = [ | ||
...collections, | ||
...keyCollections.value, | ||
]; | ||
}; | ||
|
||
watch( | ||
client, | ||
(client) => { | ||
registerSignalHandler(client, { | ||
keyCollectionsStore: { pushKeyCollection }, | ||
}); | ||
|
||
loadKeyCollections(client); | ||
}, | ||
{ immediate: true }, | ||
); | ||
const keyCollections = ref<KeyCollectionWithKeys[]>([]); | ||
|
||
const pushKeyCollection = (collection: KeyCollectionWithKeys) => { | ||
keyCollections.value.push(collection); | ||
}; | ||
|
||
return { | ||
keyCollections, | ||
pushKeyCollection, | ||
addKeyToCollection, | ||
}; | ||
const addKeyToCollection = (name: string, key: GpgKeyDist) => { | ||
const existingCollection = keyCollections.value.find( | ||
(c) => c.name === name, | ||
); | ||
if (existingCollection) { | ||
existingCollection.gpg_keys.push(key); | ||
} | ||
}; | ||
|
||
const client = inject("client") as ComputedRef<AppAgentClient>; | ||
const loadKeyCollections = async (client: AppAgentClient) => { | ||
const collections: KeyCollectionWithKeys[] = await client.callZome({ | ||
role_name: "trusted", | ||
zome_name: "trusted", | ||
fn_name: "get_my_key_collections", | ||
payload: null, | ||
cap_secret: null, | ||
}); | ||
|
||
console.log("loaded key collections", collections); | ||
|
||
keyCollections.value = [...collections, ...keyCollections.value]; | ||
}; | ||
|
||
watch( | ||
client, | ||
(client) => { | ||
registerSignalHandler(client, { | ||
keyCollectionsStore: { pushKeyCollection }, | ||
}); | ||
|
||
loadKeyCollections(client); | ||
}, | ||
{ immediate: true }, | ||
); | ||
|
||
return { | ||
keyCollections, | ||
pushKeyCollection, | ||
addKeyToCollection, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,132 @@ | ||
<script setup lang="ts"> | ||
import { GpgKeyDist } from './types'; | ||
import KeyList from '../../component/KeyList.vue'; | ||
import { useKeyCollectionsStore } from '../../store/key-collections-store'; | ||
import { ComputedRef, inject, ref, watch } from 'vue'; | ||
import CreateKeyCollection from './CreateKeyCollection.vue'; | ||
import { useNotificationsStore } from '../../store/notifications-store'; | ||
import { AppAgentClient } from '@holochain/client'; | ||
import { GpgKeyDist } from "./types"; | ||
import KeyList from "../../component/KeyList.vue"; | ||
import { useKeyCollectionsStore } from "../../store/key-collections-store"; | ||
import { ComputedRef, inject, ref, watch } from "vue"; | ||
import CreateKeyCollection from "./CreateKeyCollection.vue"; | ||
import { useNotificationsStore } from "../../store/notifications-store"; | ||
import { AppAgentClient } from "@holochain/client"; | ||
const props = defineProps<{ | ||
selectedKey: GpgKeyDist; | ||
selectedKey: GpgKeyDist; | ||
}>(); | ||
const client = inject("client") as ComputedRef<AppAgentClient>; | ||
const keyCollectionsStore = useKeyCollectionsStore(); | ||
const notificationsStore = useNotificationsStore(); | ||
const selectedCollection = ref<string>(''); | ||
const selectedCollection = ref<string>(""); | ||
const expectCreated = ref<string | null>(null); | ||
const linking = ref(false); | ||
watch(keyCollectionsStore.keyCollections, (newVal) => { | ||
watch( | ||
keyCollectionsStore.keyCollections, | ||
(newVal) => { | ||
if (newVal.length > 0) { | ||
if (expectCreated.value && newVal.map(c => c.name).indexOf(expectCreated.value) !== -1) { | ||
selectedCollection.value = expectCreated.value; | ||
expectCreated.value = null; | ||
} else { | ||
selectedCollection.value = newVal[0].name; | ||
} | ||
if ( | ||
expectCreated.value && | ||
newVal.map((c) => c.name).indexOf(expectCreated.value) !== -1 | ||
) { | ||
selectedCollection.value = expectCreated.value; | ||
expectCreated.value = null; | ||
} else { | ||
selectedCollection.value = newVal[0].name; | ||
} | ||
} | ||
}, { immediate: true }); | ||
}, | ||
{ immediate: true }, | ||
); | ||
const onKeyCollectionCreated = (name: string) => { | ||
expectCreated.value = name; | ||
expectCreated.value = name; | ||
// To reset the UI if something goes wrong, 5s might be a bit aggressive but if the signal shows up then the select will show the new collection anyway. | ||
setTimeout(() => { | ||
// If we haven't started creating a new collection, then we should clear this field | ||
if (expectCreated.value === name) { | ||
expectCreated.value = null; | ||
notificationsStore.pushNotification({ | ||
message: `New key collection '${name}' may not have been created`, | ||
type: 'warning', | ||
}); | ||
} | ||
}, 5000); | ||
// To reset the UI if something goes wrong, 5s might be a bit aggressive but if the signal shows up then the select will show the new collection anyway. | ||
setTimeout(() => { | ||
// If we haven't started creating a new collection, then we should clear this field | ||
if (expectCreated.value === name) { | ||
expectCreated.value = null; | ||
notificationsStore.pushNotification({ | ||
message: `New key collection '${name}' may not have been created`, | ||
type: "warning", | ||
}); | ||
} | ||
}, 5000); | ||
}; | ||
const addKeyToCollection = () => { | ||
if (!selectedCollection.value || !client.value || linking.value) return; | ||
if (!selectedCollection.value || !client.value || linking.value) return; | ||
linking.value = true; | ||
linking.value = true; | ||
try { | ||
client.value.callZome({ | ||
cap_secret: null, | ||
role_name: 'trusted', | ||
zome_name: 'trusted', | ||
fn_name: 'link_gpg_key_to_key_collection', | ||
payload: { | ||
gpg_key_fingerprint: props.selectedKey.fingerprint, | ||
key_collection_name: selectedCollection.value, | ||
}, | ||
}); | ||
try { | ||
client.value.callZome({ | ||
cap_secret: null, | ||
role_name: "trusted", | ||
zome_name: "trusted", | ||
fn_name: "link_gpg_key_to_key_collection", | ||
payload: { | ||
gpg_key_fingerprint: props.selectedKey.fingerprint, | ||
key_collection_name: selectedCollection.value, | ||
}, | ||
}); | ||
keyCollectionsStore.addKeyToCollection(selectedCollection.value, props.selectedKey); | ||
keyCollectionsStore.addKeyToCollection( | ||
selectedCollection.value, | ||
props.selectedKey, | ||
); | ||
notificationsStore.pushNotification({ | ||
message: `Key added to collection '${selectedCollection.value}'`, | ||
type: 'info', | ||
}); | ||
} catch (e: any) { | ||
notificationsStore.pushNotification({ | ||
message: `Error adding key to collection - ${e}`, | ||
type: 'error', | ||
timeout: 5000, | ||
}); | ||
} { | ||
linking.value = false; | ||
} | ||
} | ||
notificationsStore.pushNotification({ | ||
message: `Key added to collection '${selectedCollection.value}'`, | ||
type: "info", | ||
}); | ||
} catch (e: any) { | ||
notificationsStore.pushNotification({ | ||
message: `Error adding key to collection - ${e}`, | ||
type: "error", | ||
timeout: 5000, | ||
}); | ||
} | ||
{ | ||
linking.value = false; | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<KeyList :keys="[selectedKey]" :readonly="true"></KeyList> | ||
<KeyList :keys="[selectedKey]" :readonly="true"></KeyList> | ||
|
||
<p class="mt-5">Pick a key collection</p> | ||
<div class="join w-full"> | ||
<select v-model="selectedCollection" class="select select-bordered w-full join-item"> | ||
<option disabled value="">Select a key collection</option> | ||
<option v-for="c in keyCollectionsStore.keyCollections" v-bind:key="c.name" :value="c.name"> | ||
{{ c.name }} | ||
</option> | ||
</select> | ||
<button class="btn btn-primary join-item" :disabled="!selectedCollection" @click="addKeyToCollection">Add to collection</button> | ||
</div> | ||
<p class="mt-5">Pick a key collection</p> | ||
<div class="join w-full"> | ||
<select | ||
v-model="selectedCollection" | ||
class="select select-bordered w-full join-item" | ||
> | ||
<option disabled value="">Select a key collection</option> | ||
<option | ||
v-for="c in keyCollectionsStore.keyCollections" | ||
v-bind:key="c.name" | ||
:value="c.name" | ||
> | ||
{{ c.name }} | ||
</option> | ||
</select> | ||
<button | ||
class="btn btn-primary join-item" | ||
:disabled="!selectedCollection" | ||
@click="addKeyToCollection" | ||
> | ||
Add to collection | ||
</button> | ||
</div> | ||
|
||
<p class="mt-5">Or create a new one</p> | ||
<div v-if="expectCreated" class="flex grow justify-center"> | ||
<span class="loading loading-spinner"></span> | ||
</div> | ||
<div v-else> | ||
<CreateKeyCollection @created="onKeyCollectionCreated"></CreateKeyCollection> | ||
</div> | ||
<p class="mt-5">Or create a new one</p> | ||
<div v-if="expectCreated" class="flex grow justify-center"> | ||
<span class="loading loading-spinner"></span> | ||
</div> | ||
<div v-else> | ||
<CreateKeyCollection | ||
@created="onKeyCollectionCreated" | ||
></CreateKeyCollection> | ||
</div> | ||
</template> |
Oops, something went wrong.