Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
UI working again
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Oct 22, 2024
1 parent 08f7759 commit 11f1ad3
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 311 deletions.
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
imports = [
./zomes/integrity/notifications/zome.nix
./zomes/coordinator/notifications/zome.nix
./zomes/integrity/example/zome.nix
./zomes/coordinator/example/zome.nix
# Just for testing purposes
./workdir/dna.nix
./workdir/happ.nix
Expand Down
20 changes: 14 additions & 6 deletions tests/src/multi-device.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ test('notifications and their status get synchronized across devices for the sam

// Alice creates a Notification
await alice.store.client.sendNotification(
await sampleNotification(alice.store.client, {
recipient_profile_hash: bobProfile.actionHash,
}),
bobProfile.actionHash,
'example',
'type1',
'group1',
{
hello: 'world!',
},
);

// Wait for the created entry to be propagated to the other node.
Expand Down Expand Up @@ -115,9 +119,13 @@ test('notifications and their status get synchronized across devices for the sam

// Alice creates a Notification
await alice.store.client.sendNotification(
await sampleNotification(alice.store.client, {
recipient_profile_hash: bobProfile.actionHash,
}),
bobProfile.actionHash,
'example',
'type1',
'group1',
{
hello: 'world!',
},
);

// Wait for the created entry to be propagated to the other node.
Expand Down
40 changes: 28 additions & 12 deletions tests/src/notification-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ test('create notifications, read it, and dismiss it', async () => {

// Alice creates a Notification
await alice.store.client.sendNotification(
await sampleNotification(alice.store.client, {
recipient_profile_hash: bobProfile.actionHash,
}),
bobProfile.actionHash,
'example',
'type1',
'group1',
{
hello: 'world!',
},
);
await alice.store.client.sendNotification(
await sampleNotification(alice.store.client, {
recipient_profile_hash: bobProfile.actionHash,
}),
bobProfile.actionHash,
'example',
'type1',
'group1',
{
hello: 'world!',
},
);

// Wait for the created entry to be propagated to the other node.
Expand Down Expand Up @@ -148,14 +156,22 @@ test('create notifications and dismiss it directly', async () => {

// Alice creates a Notification
await alice.store.client.sendNotification(
await sampleNotification(alice.store.client, {
recipient_profile_hash: bobProfile.actionHash,
}),
bobProfile.actionHash,
'example',
'type1',
'group1',
{
hello: 'world!',
},
);
await alice.store.client.sendNotification(
await sampleNotification(alice.store.client, {
recipient_profile_hash: bobProfile.actionHash,
}),
bobProfile.actionHash,
'example',
'type1',
'group1',
{
hello: 'world!',
},
);

// Wait for the created entry to be propagated to the other node.
Expand Down
86 changes: 45 additions & 41 deletions ui/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
SignalWatcher,
joinAsync,
} from '@holochain-open-dev/signals';
import { AppWebsocket } from '@holochain/client';
import { AppWebsocket, decodeHashFromBase64 } from '@holochain/client';
import { ContextProvider } from '@lit/context';
import { mdiBell } from '@mdi/js';
import { decode, encode } from '@msgpack/msgpack';
Expand Down Expand Up @@ -85,36 +85,33 @@
new ContextProvider(this, profilesStoreContext, this.profilesStore);

this._notificationsStore = new NotificationsStore(
new NotificationsClient(
appClient,
'notifications_test',
),
// {
// types: {
// type1: {
// name: 'Hii',
// description: 'something',
// title(group) {
// return new Signal.State({
// status: 'completed',
// value: group,
// });
// },
// onClick: group => console.log('clicked', group),
// contents: n => {
// const i = decode(n.entry.content);

// return new Signal.State({
// status: 'completed',
// value: {
// iconSrc: wrapPathInSvg(mdiBell),
// body: i.body,
// },
// });
// },
// },
// },
// },
new NotificationsClient(appClient, 'notifications_test'),
// {
// types: {
// type1: {
// name: 'Hii',
// description: 'something',
// title(group) {
// return new Signal.State({
// status: 'completed',
// value: group,
// });
// },
// onClick: group => console.log('clicked', group),
// contents: n => {
// const i = decode(n.entry.content);

// return new Signal.State({
// status: 'completed',
// value: {
// iconSrc: wrapPathInSvg(mdiBell),
// body: i.body,
// },
// });
// },
// },
// },
// },
);
const interval = setInterval(async () => {
const allProfilesLinks =
Expand Down Expand Up @@ -147,8 +144,16 @@
this._notificationsStore.readNotifications.get(),
]);
const undismissedNotifications = [
...Array.from(result.value ? result.value[0].keys() : []),
...Array.from(result.value ? result.value[1].keys() : []),
...Array.from(
result.value
? Object.keys(result.value[0]).map(decodeHashFromBase64)
: [],
),
...Array.from(
result.value
? Object.keys(result.value[1]).map(decodeHashFromBase64)
: [],
),
];
return html`
<notifications-context .store=${this._notificationsStore}>
Expand All @@ -157,14 +162,13 @@
<div>
<sl-button
@click=${e => {
this._notificationsStore.client.sendNotification({
zome_name: "example"
notification_type: 'type1',
notification_group:
this.shadowRoot.getElementById('group').value,
recipient_profile_hash: this.peer,
content: encode({ body: "what's up?" }),
});
this._notificationsStore.client.sendNotification(
this.peer,
'example',
'type1',
this.shadowRoot.getElementById('group').value,
{ body: "what's up?" },
);
}}
>Create notification</sl-button
>
Expand Down
17 changes: 11 additions & 6 deletions ui/src/elements/my-notifications-icon-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@holochain-open-dev/profiles';
import '@holochain-open-dev/profiles/dist/elements/agent-avatar.js';
import { SignalWatcher, joinAsync } from '@holochain-open-dev/signals';
import { decodeHashFromBase64 } from '@holochain/client';
import { consume } from '@lit/context';
import { localized, msg } from '@lit/localize';
import { mdiBell } from '@mdi/js';
Expand Down Expand Up @@ -70,7 +71,9 @@ export class MyNotificationsIconButton extends SignalWatcher(LitElement) {
hoist
@sl-hide=${() =>
this.notificationsStore.client.markNotificationsAsRead(
Array.from(unreadNotifications.keys()),
Object.keys(unreadNotifications).map(hash =>
decodeHashFromBase64(hash),
),
)}
>
<div slot="trigger" style="position: relative;">
Expand All @@ -81,17 +84,19 @@ export class MyNotificationsIconButton extends SignalWatcher(LitElement) {
.src=${wrapPathInSvg(mdiBell)}
>
</sl-icon-button>
${unreadNotifications.size + readNotifications.size > 0
${Object.keys(unreadNotifications).length +
Object.keys(readNotifications).length >
0
? html`
<sl-badge
style="position: absolute; left: 16px; top: 0px; z-index: 1000"
pill
.variant=${unreadNotifications.size > 0
.variant=${Object.keys(unreadNotifications).length > 0
? 'primary'
: 'neutral'}
.pulse=${unreadNotifications.size > 0}
>${unreadNotifications.size +
readNotifications.size}</sl-badge
.pulse=${Object.keys(unreadNotifications).length > 0}
>${Object.keys(unreadNotifications).length +
Object.keys(readNotifications).length}</sl-badge
>
`
: html``}
Expand Down
Loading

0 comments on commit 11f1ad3

Please sign in to comment.