From e1574427a544a625cbe1b7cff2c40ee71a94f282 Mon Sep 17 00:00:00 2001 From: Pavel Murygin Date: Sat, 16 Jan 2021 19:32:26 +0300 Subject: [PATCH] Minor fixes. Users become online momentarily --- client/src/app/api.ts | 20 +++++++++++------- client/src/app/sync.ts | 1 - client/src/components/App.scss | 8 ++++++- client/src/components/CollaborativeEditor.tsx | 4 +--- client/src/components/UserList.tsx | 21 +++++++++---------- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/client/src/app/api.ts b/client/src/app/api.ts index 2f4bc76..5742104 100644 --- a/client/src/app/api.ts +++ b/client/src/app/api.ts @@ -42,6 +42,8 @@ const throwIfError = (result: ServiceResult) => { } }; +export type PeerId = string; + export const updateOnlineStatuses = async (client: FluenceClient) => { const particle = new Particle( ` @@ -59,7 +61,7 @@ export const updateOnlineStatuses = async (client: FluenceClient) => { (call u.$.relay_id ("op" "identity") []) (seq (call myRelay ("op" "identity") []) - (call myPeerId (fluentPadServiceId notifyOnline) [u.$.peer_id immediately]) + (call myPeerId (fluentPadServiceId notifyOnline) [u.$.peer_id]) ) ) ) @@ -77,7 +79,6 @@ export const updateOnlineStatuses = async (client: FluenceClient) => { myPeerId: client.selfPeerId.toB58String(), fluentPadServiceId: fluentPadServiceId, notifyOnline: notifyOnlineFnName, - immediately: false, }, ); @@ -95,7 +96,7 @@ export const notifySelfAdded = (client: FluenceClient, name: string) => { (par (seq (call u.$.relay_id ("op" "identity") []) - (call u.$.peer_id (fluentPadServiceId notifyUserAdded) [myUser]) + (call u.$.peer_id (fluentPadServiceId notifyUserAdded) [myUser setOnline]) ) (next u) ) @@ -110,11 +111,14 @@ export const notifySelfAdded = (client: FluenceClient, name: string) => { myPeerId: client.selfPeerId.toB58String(), fluentPadServiceId: fluentPadServiceId, notifyUserAdded: notifyUserAddedFnName, - myUser: { - name: name, - peer_id: client.selfPeerId.toB58String(), - relay_id: client.relayPeerID.toB58String(), - }, + myUser: [ + { + name: name, + peer_id: client.selfPeerId.toB58String(), + relay_id: client.relayPeerID.toB58String(), + }, + ], + setOnline: true, }, ); diff --git a/client/src/app/sync.ts b/client/src/app/sync.ts index c84f54f..960c0e9 100644 --- a/client/src/app/sync.ts +++ b/client/src/app/sync.ts @@ -61,7 +61,6 @@ export class SyncClient { private doHandleDocUpdate(docId: string, doc: Doc) { if (docId === SyncClient.globalDocId && this.handleDocUpdate) { - console.log(docId, doc); this.handleDocUpdate(doc); } } diff --git a/client/src/components/App.scss b/client/src/components/App.scss index 2ef9a16..5ae7dc6 100644 --- a/client/src/components/App.scss +++ b/client/src/components/App.scss @@ -200,12 +200,18 @@ body { text-transform: uppercase; background: none; - border: none; + border-top: none; + border-right: none; + border-left: none; + border-bottom: 1px solid $accent-color; text-decoration: none; + outline: none; + &:hover, &:focus { color: $accent-color; + border-bottom: 2px solid $accent-color; } } } diff --git a/client/src/components/CollaborativeEditor.tsx b/client/src/components/CollaborativeEditor.tsx index 72a0fe0..fa780b5 100644 --- a/client/src/components/CollaborativeEditor.tsx +++ b/client/src/components/CollaborativeEditor.tsx @@ -23,17 +23,15 @@ export const CollaborativeEditor = () => { useEffect(() => { syncClient.syncDoc(initDoc()); syncClient.handleDocUpdate = (doc) => { - console.log('syncClient.handleDocUpdate'); setText(doc.text.toString()); }; syncClient.handleSendChanges = (changes: string) => { - console.log('syncClient.handleSendChanges'); api.addEntry(client, changes); }; const unsub = subscribeToEvent(client, fluentPadServiceId, notifyTextUpdateFnName, (args, tetraplets) => { - const [authorPeerId, changes, isAuthorized] = args; + const [authorPeerId, changes, isAuthorized] = args as [api.PeerId, string, boolean]; if (authorPeerId === client.selfPeerId.toB58String()) { return; } diff --git a/client/src/components/UserList.tsx b/client/src/components/UserList.tsx index 3eee79b..877e3e9 100644 --- a/client/src/components/UserList.tsx +++ b/client/src/components/UserList.tsx @@ -8,8 +8,7 @@ import { import { useFluenceClient } from '../app/FluenceClientContext'; import * as api from 'src/app/api'; import { subscribeToEvent } from '@fluencelabs/fluence'; - -type PeerId = string; +import { PeerId } from 'src/app/api'; interface User { id: PeerId; @@ -46,7 +45,7 @@ export const UserList = (props: { selfName: string }) => { }, refreshTimeoutMs); const unsub1 = subscribeToEvent(client, fluentPadServiceId, notifyUserAddedFnName, (args, _) => { - const users = args.flatMap((x) => x).flatMap((x) => x) as api.User[]; + const [users, setOnline] = args as [api.User[], boolean]; setUsers((prev) => { const result = new Map(prev); for (let u of users) { @@ -59,8 +58,8 @@ export const UserList = (props: { selfName: string }) => { result.set(u.peer_id, { name: u.name, id: u.peer_id, - isOnline: isCurrentUser, - shouldBecomeOnline: isCurrentUser, + isOnline: isCurrentUser || setOnline, + shouldBecomeOnline: isCurrentUser || setOnline, }); } return result; @@ -68,7 +67,7 @@ export const UserList = (props: { selfName: string }) => { }); const unsub2 = subscribeToEvent(client, fluentPadServiceId, notifyUserRemovedFnName, (args, _) => { - const users = args.flatMap((x) => x) as PeerId[]; + const [users] = args as [PeerId[]]; setUsers((prev) => { const result = new Map(prev); for (let u of users) { @@ -79,14 +78,14 @@ export const UserList = (props: { selfName: string }) => { }); const unsub3 = subscribeToEvent(client, fluentPadServiceId, notifyOnlineFnName, (args, _) => { - const [[peerId], immediately] = args; + const [users] = args as [PeerId[]]; setUsers((prev) => { const result = new Map(prev); - const toSetOnline = result.get(peerId); - if (toSetOnline) { - toSetOnline.shouldBecomeOnline = true; - if (immediately) { + for (let u of users) { + const toSetOnline = result.get(u); + if (toSetOnline) { + toSetOnline.shouldBecomeOnline = true; toSetOnline.isOnline = true; } }