Skip to content

Commit

Permalink
update profiles, and now add tree meta document
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Dec 5, 2023
1 parent 3548c2b commit f19c2ab
Show file tree
Hide file tree
Showing 11 changed files with 648 additions and 149 deletions.
702 changes: 575 additions & 127 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
"@open-wc/scoped-elements": "^2.1.4",
"@shoelace-style/shoelace": "^2.5.2",
"@fortawesome/free-solid-svg-icons": "^6.3.0",
"@holochain-open-dev/elements": "^0.7.0",
"@holochain-open-dev/profiles": "^0.16.0",
"@holochain-open-dev/file-storage": "^0.6.1",
"@holochain-open-dev/stores": "^0.6.0",
"@holochain-open-dev/utils": "^0.15.0",
"@holochain/client": "^0.16",
"@lightningrodlabs/we-applet": "0.9.0",
"@holochain-open-dev/elements": "^0.8.4",
"@holochain-open-dev/profiles": "^0.17.3",
"@holochain-open-dev/stores": "^0.8.3",
"@holochain-open-dev/utils": "^0.16.0",
"@holochain/client": "0.16",
"@lightningrodlabs/we-applet": "0.11.0",
"@lit-labs/context": "^0.2.0",
"@lit/localize": "^0.11.4",
"lit": "^2.7.0",
Expand Down
7 changes: 5 additions & 2 deletions ui/src/elements/how-agent-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ export class HowAgentList extends LitElement {
const agentsHTML: Array<TemplateResult>= []
for (const agentHash of this.agents) {
let profile: Profile |undefined = undefined
if (this._allProfiles.value.status == "complete")
profile = this._allProfiles.value.value.get(decodeHashFromBase64(agentHash))
if (this._allProfiles.value.status == "complete") {
const record = this._allProfiles.value.value.get(decodeHashFromBase64(agentHash))
if (record)
profile = record.entry
}

if (profile) {
agentsHTML.push(html`<div class="agent" title="${agentHash}"><agent-avatar agent-pub-key=${agentHash}> </agent-avatar> ${profile.nickname}</div>`)
Expand Down
9 changes: 5 additions & 4 deletions ui/src/elements/how-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { initialTreeSimple } from "../initSimple";
import { HowUnitDialog } from "./how-unit-dialog";
import { ScopedElementsMixin } from "@open-wc/scoped-elements";
import {HowDocument } from "./how-document";
import { AsyncStatus, StoreSubscriber } from '@holochain-open-dev/stores';
import { AsyncReadable, AsyncStatus, StoreSubscriber } from '@holochain-open-dev/stores';
import { aliveImage } from "../images";
import '@shoelace-style/shoelace/dist/components/dialog/dialog.js';
import '@shoelace-style/shoelace/dist/components/button/button.js';
Expand All @@ -34,6 +34,7 @@ import {
import {EntryHashB64, encodeHashToBase64} from "@holochain/client";
import { consume } from '@lit-labs/context';
import { HowMyProfileDialog } from "./how-my-profile-dialog";
import { EntryRecord } from "@holochain-open-dev/utils";
//import { HowSettings } from "./how-settings";
//import './how-settings.js';

Expand All @@ -58,7 +59,7 @@ export class HowController extends ScopedElementsMixin(LitElement) {
_profiles!: ProfilesStore;


_myProfile!: StoreSubscriber<AsyncStatus<Profile | undefined>>;
_myProfile!: StoreSubscriber<AsyncStatus<EntryRecord<Profile> | undefined>>;
@query("how-my-profile")
_myProfileDialog!:HowMyProfileDialog

Expand Down Expand Up @@ -114,15 +115,15 @@ export class HowController extends ScopedElementsMixin(LitElement) {
if (this._myProfile.value.status == "complete") {
const profile = this._myProfile.value.value;
if (profile)
return profile.nickname
return profile.entry.nickname
}
return ""
}
get myAvatar(): string {
if (this._myProfile.value.status == "complete") {
const profile = this._myProfile.value.value;
if (profile)
return profile.fields.avatar
return profile.entry.fields.avatar
}
return ""
}
Expand Down
6 changes: 3 additions & 3 deletions ui/src/elements/how-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ export class HowTree extends ScopedElementsMixin(LitElement) {
buildTree(node: Node):any {
const unitInfo = this.getUnitInfo(node)
const nodeId = unitInfo ? encodeHashToBase64(unitInfo.hash) : node.id
//const documentsMap = this._documents.value
//const docs = node.val.documents.map(hash => documentsMap[encodeHashToBase64(hash)])
const documentsMap = this._documents.value
// const docs = node.val.documents.map(hash => documentsMap[encodeHashToBase64(hash)])
const state = node.val.units.length ? node.val.units[0].state : ""// docs[docs.length-1]? docs[docs.length-1].state : ""
return html`
<li class="${this.treeType}">
<span class="${nodeId == this.currentNode ? "current" : ""}" @click=${()=>this.select(nodeId)}>
<div class="progress" title=${`document count: ${node.val.documents.length}`}>
<how-node .unit=${this._units.value[nodeId]} state=${state}> </how-node>
</div>
${node.id=="0" ? "Holochain Community Standards" : node.val.name}
${node.id=="0" ? this._store.treeName : node.val.name}
<!-- <mwc-button icon="add_circle" @click=${
() => this.dispatchEvent(new CustomEvent('add-child', { detail: nodeId, bubbles: true, composed: true }))}>
</mwc-button> -->
Expand Down
8 changes: 6 additions & 2 deletions ui/src/elements/how-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
const created = new Date(action.timestamp)
const creatorHash = encodeHashToBase64(action.author)
let creator: Profile |undefined = undefined
if (this._allProfiles.value.status == "complete")
creator = this._allProfiles.value.value.get(action.author)
if (this._allProfiles.value.status == "complete") {
const record = this._allProfiles.value.value.get(action.author)
if (record) {
creator = record.entry
}
}
let stateHTML
let controlsHTML:any[] = []

Expand Down
4 changes: 2 additions & 2 deletions ui/src/holochain-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ export class HolochainApp extends ScopedElementsMixin(LitElement) {
const appAgentClient = await AppAgentWebsocket.connect(new URL(url), appId)

this._howStore = new HowStore(appAgentClient, "how")



this._profilesStore = new ProfilesStore(
new ProfilesClient(appAgentClient, 'how'), config
Expand All @@ -90,10 +88,12 @@ export class HolochainApp extends ScopedElementsMixin(LitElement) {
const client = weClient.renderInfo.appletClient;
this._howStore = new HowStore(client, "how")


//@ts-ignore
const profilesClient = weClient.renderInfo.profilesClient;
this._profilesStore = new ProfilesStore(profilesClient, config)
}
this._howStore.initialize()

this.loaded = true;
}
Expand Down
17 changes: 15 additions & 2 deletions ui/src/how.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class HowStore {

/** Static info */
myAgentPubKey: AgentPubKeyB64;
treeName: string = ""
config = {}

/** Readable stores */
public units: Readable<Dictionary<Unit>> = derived(this.unitsStore, i => i)
Expand Down Expand Up @@ -74,7 +76,7 @@ export class HowStore {
this.service = new HowService(client, roleName, zomeName);

client.on( 'signal', signal => {
console.log("SIGNAL",signal)
console.log("SIGNAL",signal.payload)
const payload = signal.payload as HowSignal
switch(payload.message.type) {
case "NewUnit":
Expand Down Expand Up @@ -139,7 +141,9 @@ export class HowStore {
return units
})
this.unitsActionStore.update(units => {
units[hash] = record.action
const a = record.action
//@ts-ignore
units[hash] = a
return units
})
this.unitsInfoStore.update(units => {
Expand Down Expand Up @@ -203,6 +207,15 @@ export class HowStore {
}
}
}

async initialize() {
const docs = await this.pullDocuments("")
const meta = docs.find(d=>d.content.documentType == DocType.TreeMeta)
if (meta) {
this.treeName = meta.content.content[0].name
this.config = JSON.parse(meta.content.content[0].content)
}
}

async pullDocuments(path: string) : Promise<Array<DocumentOutput>> {
let documents = await this.service.getDocuments(path)
Expand Down
15 changes: 15 additions & 0 deletions ui/src/initHolochain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ export function initialTreeHolochain(progenitor: AgentPubKeyB64) {
})],
],
documents: [
{
path: "",
documentType: DocType.TreeMeta,
content: [
{
name: "Holochain Community Standards",
sourcePath: SourceManual,
sectionType: SectionType.Content,
contentType: "text/plain",
content: '{"foo":"bar"}',
},
],
editors: [progenitor],
meta: {}
},
{
path: "",
documentType: DocType.Document,
Expand Down
15 changes: 15 additions & 0 deletions ui/src/initSimple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ export function initialTreeSimple(progenitor: AgentPubKeyB64) {
})],
],
documents: [
{
path: "",
documentType: DocType.TreeMeta,
content: [
{
name: "Alignments",
sourcePath: SourceManual,
sectionType: SectionType.Content,
contentType: "text/plain",
content: '{"foo":"bar"}',
},
],
editors: [progenitor],
meta: {}
},
{
path: "",
documentType: DocType.Document,
Expand Down
1 change: 1 addition & 0 deletions ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export enum VersioningType {
}

export enum DocType {
TreeMeta = "_",
Document = "_document",
Comment = "_comment"
}
Expand Down

0 comments on commit f19c2ab

Please sign in to comment.