import React, {Component} from 'react'; import classnames from 'classnames'; import GravatarImg from '../GravatarImg'; import Modal from '../base/Modal'; import PromptButton from '../base/PromptButton'; import ModalBody from '../base/ModalBody'; import ModalHeader from '../base/ModalHeader'; import ModalFooter from '../base/ModalFooter'; import {Tab, Tabs, TabList, TabPanel} from 'react-tabs'; import * as session from '../../../backend/sync/session'; import * as syncStorage from '../../../backend/sync/storage'; import * as sync from '../../../backend/sync'; import * as db from '../../../backend/database'; class SyncModal extends Component { constructor (props) { super(props); this.state = { firstName: 'n/a', email: 'n/a', sessionId: 'n/a', dirty: [], workspaceData: [] } } async _handleEnableSync (workspaceData) { console.log('Enable sync', workspaceData); } async _handleReset () { for (const r of await syncStorage.allResources()) { await syncStorage.removeResource(r); } await session.logout(); this.hide(); } _handleLogout () { session.logout(); this.hide(); } async _updateModal () { const workspaces = await db.workspace.all(); const workspaceData = []; for (const doc of workspaces) { const resource = await syncStorage.getResourceById(doc._id); workspaceData.push({doc, resource}); } const totalResources = (await syncStorage.allResources()).length; const numDirty = (await syncStorage.findDirtyResources()).length; const numSynced = totalResources - numDirty; const percentSynced = parseInt(numSynced / totalResources * 10) / 10 * 100 || 0; this.setState({ workspaceData, numDirty, numSynced, totalResources, percentSynced, email: session.getEmail(), firstName: session.getFirstName(), sessionId: session.getCurrentSessionId(), }); } async show () { if (!session.isLoggedIn()) { console.error('Not logged in'); return; } clearInterval(this._interval); this._interval = setInterval(() => this._updateModal(), 2000); await this._updateModal(); this.modal.show(); } hide () { clearInterval(this._interval); this.modal.hide(); } render () { const s = this.state; const data = [ ['Status', `${s.numSynced}/${s.totalResources} (${s.percentSynced}%)`], ['Session', s.sessionId.slice(0, 30)], ['Full Sync', `${sync.FULL_SYNC_INTERVAL / 1000} second interval`], ['Partial Sync', `${sync.DEBOUNCE_TIME / 1000} seconds after change`], ]; const colors = { debug: 'info', warn: 'warning', error: 'danger' }; // Show last N logs const allLogs = sync.logger.tail(); const logs = allLogs.slice(allLogs.length - 2000); return ( this.modal = m} tall={true} wide={true}> Sync Settings {" "} ({s.email})

Hi {this.state.firstName}!

You are currently signed in with {" "} {this.state.email}


Welcome to the beta

The sync beta is

Team

This is where you configure your team

{this.state.workspaceData.map(wd => ( ))}
Sync Created By Name Members
{(wd.resource || {}).createdBy === session.getAccountId() ? 'You' : 'Someone Else'} {wd.doc.name}

Here is some useful debug info in case you need to report a bug.

{data.map(([label, value]) => ( ))}
{label} {value}
{logs.map((entry, i) => { function pad (n, length) { let s = n + ''; while (s.length < length) { s = '0' + s; } return s; } const dateString = pad(entry.date.getFullYear(), 4) + '/' + pad(entry.date.getMonth(), 2) + '/' + pad(entry.date.getDay(), 2) + ' ' + pad(entry.date.getHours(), 2) + ':' + pad(entry.date.getMinutes(), 2) + ':' + pad(entry.date.getSeconds(), 2); return (
                      {dateString}
                      {" "}
                      
                      [{entry.type}]
                    
                      {" "}
                      {entry.message}
                    
) })}
this._handleLogout()}> Logout this._handleReset()} confirmMessage="Delete all sync-related data?"> Reset Sync Account
) } } SyncModal.propTypes = {}; export default SyncModal;