Skip to content

Commit

Permalink
Group together user settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Jul 31, 2021
1 parent 464c6da commit ad79f6b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/components/block-editor-contents/use-yjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ async function initYDoc( { blocks, onRemoteDataChange, settings, getSelection, s

/** @type string */
const identity = uuidv4();
const caretColor = settings.caretColor || sample( defaultColors );

debug( `initYDoc (identity: ${ identity })` );

Expand Down Expand Up @@ -93,9 +92,11 @@ async function initYDoc( { blocks, onRemoteDataChange, settings, getSelection, s

return transport
.connect( {
identity,
username: settings.username,
caretColor,
user: {
identity,
name: settings.username,
color: settings.caretColor || sample( defaultColors ),
},
onReceiveMessage,
setAvailablePeers: ( peers ) => {
debug( 'setAvailablePeers', peers );
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ import './style.scss';
* @property {() => Promise<void>} disconnect
*
* @typedef CollaborationTransportConnectOpts
* @property {string} identity
* @property {string} username
* @property {string} caretColor Color of the caret indicator displayed to peers.
* @property {object} user
* @property {string} user.identity
* @property {string} user.name
* @property {string} user.color Color of the caret indicator displayed to peers.
* @property {(message: object) => void} onReceiveMessage Callback to run when a message is received.
* @property {(peers: AvailablePeer[]) => void} setAvailablePeers Callback to run when peers change.
* @property {string} [channelId]
Expand Down
4 changes: 2 additions & 2 deletions stories/collab/mock-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const mockTransport = {
sendMessage: ( data ) => {
window.localStorage.setItem( 'isoEditorYjsMessage', JSON.stringify( data ) );
},
connect: ( { identity, username, caretColor, onReceiveMessage, setAvailablePeers, channelId } ) => {
connect: ( { user: { identity, name, color }, onReceiveMessage, setAvailablePeers, channelId } ) => {
listeners.push(
{
event: 'storage',
Expand Down Expand Up @@ -39,7 +39,7 @@ const mockTransport = {

window.localStorage.setItem(
'isoEditorYjsPeers',
JSON.stringify( [ ...peers, { id: identity, name: username, color: caretColor } ] )
JSON.stringify( [ ...peers, { id: identity, name, color } ] )
);

disconnectHandlers.push( () => {
Expand Down

0 comments on commit ad79f6b

Please sign in to comment.