Skip to content

Commit

Permalink
make compatible with current Moss and add status labels
Browse files Browse the repository at this point in the history
  • Loading branch information
LeosPrograms committed May 6, 2024
1 parent 7a08cf8 commit fec6804
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 163 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"start": "AGENTS=2 npm run network",
"online": "AGENTS=2 npm run online:network",
"dev": "VITE_ADMIN_PORT=$(port) VITE_APP_PORT=$(port) SIGNAL_PORT=$(port) BOOTSTRAP_PORT=$(port) UI_PORT=8888 npm run x",
"dev:online": "VITE_ADMIN_PORT=$(port) VITE_APP_PORT=$(port) SIGNAL_PORT=$(port) BOOTSTRAP_PORT=$(port) UI_PORT=8888 npm run x",
"x": "hc s clean && npm run build:happ && UI_PORT=8888 concurrently \"npm start -w ui\" \"npm run start:happ\" \"hc run-local-services -b $BOOTSTRAP_PORT -s $SIGNAL_PORT\"",
"x:online": "hc s clean && npm run build:happ && UI_PORT=8888 concurrently \"npm start -w ui\" \"npm run start:happ\" \"hc run-local-services -b $BOOTSTRAP_PORT -s $SIGNAL_PORT\"",
"tool-dev": " UI_PORT=8888 npm run tool-devy",
"tool-devy": "concurrently \"npm start -w ui\" \"sleep 1 && we-dev-cli --agent-idx 1 --dev-config we_dev/config.ts\" \"sleep 10 && we-dev-cli --agent-idx 2 --dev-config we_dev/config.ts\"",
"tool-devx": "BPORT=46263 SPORT=46262; concurrently \"hc run-local-services -b $BPORT -s $SPORT\" \"npm start -w ui\" \"./we_dev/we.AppImage --dev-config we_dev/config.json --agent-num 1 -b http://127.0.0.1:$BPORT -s ws://127.0.0.1:$SPORT\" \"sleep 10 && ./we_dev/we.AppImage --dev-config we_dev/config.json --agent-num 2 -b http://127.0.0.1:$BPORT -s ws://127.0.0.1:$SPORT\"",
Expand All @@ -18,7 +20,7 @@
"test": "npm run build:zomes && hc app pack workdir --recursive && npm t -w tests",
"launch:happ": "echo \"pass\" | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/whosin.happ --ui-port $UI_PORT network mem",
"launch:online2": "echo \"pass\" | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/whosin.happ --ui-port $UI_PORT network webrtc \"wss://127.0.0.1:18929\"",
"launch:online": "echo \"pass\" | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/whosin.happ --ui-port $UI_PORT network --bootstrap https://bootstrap.holo.host webrtc wss://signal.holo.host",
"launch:online": "echo \"pass\" | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/whosin.happ --ui-port $UI_PORT network --bootstrap https://bootstrap-2.infra.holochain.org webrtc wss://signal-2.infra.holochain.org",
"package": "npm run build:happ && npm run package -w ui && hc web-app pack workdir --recursive",
"build:happ": "npm run build:zomes && hc app pack workdir --recursive",
"build:zomes": "RUSTFLAGS='' CARGO_TARGET_DIR=target cargo build --release --target wasm32-unknown-unknown"
Expand Down
29 changes: 22 additions & 7 deletions ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,27 @@
case "block":
switch(weClient.renderInfo.view.block) {
case "active_boards":
renderType = RenderType.BlockActiveBoards
currentView = "dashboard"
break;
default:
throw new Error("Unknown applet-view block type:"+weClient.renderInfo.view.block);
}
break;
case "attachable":
case "creatable":
switch (weClient.renderInfo.view.name) {
case "Coordination":
currentView = "create-coordination-mini"
}
break;
case "asset":
switch (weClient.renderInfo.view.roleName) {
case "whosin":
switch (weClient.renderInfo.view.integrityZomeName) {
case "coordinator_integrity":
switch (weClient.renderInfo.view.entryType) {
case "coordination":
currentView = "coordination"
currentHash = weClient.renderInfo.view.hrlWithContext.hrl[1]
currentHash = weClient.renderInfo.view.wal.hrl[1]
// console.log("weClient.renderInfo.view", weClient.renderInfo.view)
// hrlWithContext = weClient.renderInfo.view.hrlWithContext
break;
Expand Down Expand Up @@ -301,7 +307,10 @@

<NotificationsHandler></NotificationsHandler>
<main style="width: 100vw;">
<Header></Header>

{#if currentView != "create-coordination-mini"}
<Header></Header>
{/if}

{#if !loading && !notifier && allNotifiers.length > 1 && !(["notifier", "notificant", "home", "create-coordination"].includes(String(currentView)))}
<p class="notice" style="margin: auto; border-radius: 0 0 4px 4px">Want to receive texts or emails when coordinations reach minimum participation?
Expand All @@ -320,10 +329,16 @@
<div class="white-container" style="display: flex; flex-direction: column; margin-top: 30px;" in:fade={{duration: 200}} out:fade={{duration: 100}}>
<CoordinationDetail coordinationHash={currentHash}></CoordinationDetail>
</div>
{:else if currentView == "create-coordination-mini"}
<div style="padding: 10px;">
<CreateCoordination></CreateCoordination>
</div>
{:else if currentView == "create-coordination"}
<span in:fade={{duration: 200}} out:fade={{duration: 100}}>
<CreateCoordination></CreateCoordination>
</span>
<span in:fade={{duration: 200}} out:fade={{duration: 100}}>
<div class="white-container" style="display: flex; flex-direction: column; margin-top: 30px;">
<CreateCoordination></CreateCoordination>
</div>
</span>
<!-- HI -->
{:else if currentView == "notifications"}
<span in:fade={{duration: 200}} out:fade={{duration: 100}}>
Expand Down
39 changes: 20 additions & 19 deletions ui/src/AttachmentsBind.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// import type { GamezSignal, GamezStore } from "./store";
// import type { Board } from "./board";
import SvgIcon from "./SvgIcon.svelte";
import type { AppletInfo, AttachmentType } from "@lightningrodlabs/we-applet";
import type { AppletInfo } from "@lightningrodlabs/we-applet";
import { HoloHashMap, type EntryHashMap } from "@holochain-open-dev/utils";
import type { EntryHash } from "@holochain/client";
import { hashEqual } from "./util";
Expand All @@ -19,58 +19,59 @@
weClient = value;
});
type AppletTypes = {
appletName: string,
attachmentTypes: Record<string,AttachmentType>
}
// type AppletTypes = {
// appletName: string,
// attachmentTypes: Record<string,AttachmentType>
// }
type Groups = {
logo_src: string,
name: string,
}
let groups: HoloHashMap<EntryHash, Groups> = new HoloHashMap
let allGroups: HoloHashMap<EntryHash, Groups> = new HoloHashMap
let appletInfos: HoloHashMap<EntryHash, AppletInfo> = new HoloHashMap
$: attachmentTypes= []
$: groups
$: allGroups
export const refresh = async () => {
console.log("refresh")
console.log(weClient.attachmentTypes)
// console.log("refresh")
// console.log(weClient.attachmentTypes)
attachmentTypes = Array.from(weClient.attachmentTypes.entries())
console.log(attachmentTypes)
groups = new HoloHashMap
allGroups = new HoloHashMap<EntryHash, Groups>
appletInfos = new HoloHashMap
for (const [hash, aType] of attachmentTypes) {
let appletInfo = appletInfos.get(hash)
if (!appletInfo) {
appletInfo = await weClient.appletInfo(hash)
appletInfos.set(hash, appletInfo)
// if (appletInfo.appletName === "threads") {
// threadsInfos.set(hash, appletInfo)
// }
}
console.log(appletInfo)
// console.log("88888",appletInfo)
for (const groupHash of appletInfo.groupsIds) {
let groupTypes = weClient.attachmentTypes.get(groupHash)
if (!groupTypes) {
const profile = await weClient.groupProfile(groupHash)
groups.set(groupHash, {
allGroups.set(groupHash, {
logo_src: profile.logo_src,
name: profile.name,
})
}
}
}
groups = groups
allGroups = allGroups
attachmentTypes = attachmentTypes
}
}
</script>

{#if false}
{JSON.stringify(weClient)}
{#if true}
<div>
<h3>Create Bound Item From:</h3>
{#each Array.from(groups.entries()) as [groupHash, group]}
<!-- {JSON.stringify(groupHash)} -->
<!-- <h3>Create Bound Item From:</h3> -->
{#each Array.from(allGroups.entries()) as [groupHash, group]}
<!-- {#if group.name} -->
<div style="display:flex;flex-direction:column">
<div style="display:flex;align-items:center;">
Expand Down
50 changes: 32 additions & 18 deletions ui/src/AttachmentsDialog.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<script lang="ts">
import { type HrlB64WithContext, isWeContext, type HrlWithContext } from "@lightningrodlabs/we-applet";
import { isWeContext, type WAL, weaveUrlFromWal } from "@lightningrodlabs/we-applet";
import { cloneDeep } from "lodash";
// import type { Board, Piece } from "./board";
import { getContext, onMount } from "svelte";
// import type { GamezStore } from "./store";
import { hrlWithContextToB64} from "./util";
import SvgIcon from "./SvgIcon.svelte";
import '@shoelace-style/shoelace/dist/components/button/button.js';
import '@shoelace-style/shoelace/dist/components/dialog/dialog.js';
import AttachmentsList from "./AttachmentsList.svelte";
import AttachmentsBind from "./AttachmentsBind.svelte";
// import AttachmentsBind from "./AttachmentsBind.svelte";
import { weClientStored } from './store.js';
import { createEventDispatcher } from 'svelte';
import type { WALUrl } from "./util";
// const { getStore } :any = getContext("gzStore");
// let store: GamezStore = getStore();
// let piece: Piece | undefined
export let attachments: Array<HrlB64WithContext> = []
export let attachmentsLimit: number = Infinity;
export let attachments: Array<WALUrl>
const dispatch = createEventDispatcher();
let weClient;
Expand Down Expand Up @@ -53,15 +54,20 @@
}
const addAttachment = async () => {
const hrl = await weClient.userSelectHrl()
if (hrl) {
_addAttachment(hrl)
const wal = await weClient.userSelectWal()
if (wal) {
_addAttachment(wal)
}
}
const _addAttachment = (hrl: HrlWithContext) => {
attachments.push(hrlWithContextToB64(hrl))
const _addAttachment = (wal: WAL) => {
if (attachmentsLimit == attachments.length) {
removeAttachment(0)
}
attachments.push(weaveUrlFromWal(wal))
attachments = attachments
// dispatch
dispatch('add-attachment', weaveUrlFromWal(wal))
// handleSave()
}
Expand All @@ -80,10 +86,9 @@
// }
// }
onMount(async () => {
bind.refresh()
dialog.show()
})
// onMount(async () => {
// bind.refresh()
// })
</script>

<!-- <sl-dialog label="Add links" bind:this={dialog}> -->
Expand All @@ -96,11 +101,20 @@
<SvgIcon icon=link size=16/>
</button>

<AttachmentsBind
bind:this = {bind}
on:add-binding={(e)=>_addAttachment(e.detail)}
/>

<!-- <button on:click={() => {dialog.show(); bind.refresh()}}>
<SvgIcon icon=faPlus size=16/>
</button>
<sl-dialog label="Create bound item from:" bind:this={dialog}>
<AttachmentsBind
bind:this = {bind}
on:add-binding={(e)=>{
console.log(e.detail);
_addAttachment(e.detail);
}}
/>
</sl-dialog> -->

<div style="display:block; width: 100%">
<AttachmentsList attachments={attachments}
on:remove-attachment={(e)=>removeAttachment(e.detail)}/>
Expand Down
58 changes: 34 additions & 24 deletions ui/src/AttachmentsList.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<script lang="ts">
import "@shoelace-style/shoelace/dist/components/skeleton/skeleton.js";
import { createEventDispatcher, getContext } from "svelte";
import { hrlB64WithContextToRaw } from "./util";
import type { HrlB64WithContext } from "@lightningrodlabs/we-applet";
import { weaveUrlToWAL } from "@lightningrodlabs/we-applet";
import { clientContext } from './contexts';
import { weClientStored } from './store.js';
import type { EntryHash, Record, AgentPubKey, ActionHash, AppAgentClient, NewEntryAction } from '@holochain/client';
import { WeClient, isWeContext, initializeHotReload, type HrlWithContext, type Hrl } from '@lightningrodlabs/we-applet';
import type { AppletHash, AppletServices, AssetInfo, WAL, WeServices } from '@lightningrodlabs/we-applet';
import SvgIcon from "./SvgIcon.svelte";
import type { WALUrl } from "./util";
const dispatch = createEventDispatcher()
export let attachments: Array<HrlB64WithContext>
export let attachments: Array<WALUrl>
export let allowDelete = true
let weClient;
Expand All @@ -20,36 +20,46 @@
});
</script>

<div class="attachments-list">
{#each attachments as attachment, index}
{#each attachments as wal, index}
<div
class:attachment-item-with-delete={allowDelete}
class:attachment-item={!allowDelete}
>
{#await weClient.attachableInfo(hrlB64WithContextToRaw(attachment))}

{#await weClient.assetInfo(weaveUrlToWAL(wal))}
<sl-button size="small" loading></sl-button>
{:then { attachableInfo }}
<sl-button size="small"
on:click={(e)=>{
e.stopPropagation()
const hrlWithContext = hrlB64WithContextToRaw(attachment)
weClient.openHrl(hrlWithContext)
}}
style="display:flex;flex-direction:row;margin-right:5px"><sl-icon src={attachableInfo.icon_src} slot="prefix"></sl-icon>
{attachableInfo.name}
</sl-button>
{#if allowDelete}
<sl-button size="small"
on:click={()=>{
dispatch("remove-attachment",index)
}}
>
<SvgIcon icon=faTrash size=12 />
{:then data}
{#if data}
{@const assetInfo = data.assetInfo}
<sl-button size="small"
on:click={async (e)=>{
e.stopPropagation()
try {
await weClient.openWal(weaveUrlToWAL(wal))
} catch(e) {
alert(`Error opening link: ${e}`)
}
}}
style="display:flex;flex-direction:row;margin-right:5px"><sl-icon src={assetInfo.icon_src} slot="prefix"></sl-icon>
{assetInfo.name}
</sl-button>
{:else}
<div style="color:red; cursor:pointer; padding: 0 5px 0 5px; border: dashed 1px;margin-right:5px" title={`Failed to resolve WAL: ${hrlToString(wal.hrl)}?${JSON.stringify(wal.context)}`}>Bad WAL</div>
{/if}
{:catch error}
Oops. something's wrong.
<div style="color:red">Error getting asset info: {error}</div>
{/await}
{#if allowDelete}
<sl-button size="small"
on:click={()=>{
dispatch("remove-attachment",index)
}}
>
<SvgIcon icon=faTrash size=12 />
</sl-button>
{/if}
</div>
{/each}
</div>
Expand Down
Loading

0 comments on commit fec6804

Please sign in to comment.