From fec5646229d371e11ec648f22d29182bfd7d6836 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Fri, 22 May 2020 14:22:11 -0400 Subject: [PATCH] js: reworked store/reducer patterns --- pkg/interface/src/App.js | 10 +- .../{apps/publish/api.js => api/publish.js} | 72 ++------------ .../src/apps/chat/{ChatApp.js => app.js} | 2 +- pkg/interface/src/apps/chat/store.js | 73 -------------- .../src/apps/dojo/{DojoApp.js => app.js} | 0 .../src/apps/groups/{GroupsApp.js => app.js} | 4 +- .../apps/groups/reducers/metadata-update.js | 71 -------------- pkg/interface/src/apps/groups/store.js | 66 ------------- .../src/apps/links/{LinksApp.js => app.js} | 4 +- pkg/interface/src/apps/links/store.js | 81 --------------- .../apps/publish/{PublishApp.js => app.js} | 6 +- .../src/apps/publish/reducers/group.js | 68 ------------- .../src/apps/publish/reducers/initial.js | 7 -- .../src/apps/publish/reducers/invite.js | 58 ----------- .../src/apps/publish/reducers/permission.js | 58 ----------- pkg/interface/src/apps/publish/store.js | 67 ------------- pkg/interface/src/oldApps/chat/tile/tile.js | 60 ------------ pkg/interface/src/oldApps/groups/tile/tile.js | 58 ----------- .../src/oldApps/link-webext/background.js | 92 ------------------ .../link-webext/browserAction/index.html | 11 --- .../link-webext/browserAction/script.js | 1 - .../link-webext/browserAction/style.css | 3 - .../src/oldApps/link-webext/icons/icon.png | Bin 979 -> 0 bytes .../src/oldApps/link-webext/manifest.json | 39 -------- .../oldApps/link-webext/options/index.html | 22 ----- .../src/oldApps/link-webext/options/script.js | 21 ---- .../src/oldApps/link-webext/options/style.css | 3 - .../src/oldApps/link-webext/storage.js | 20 ---- pkg/interface/src/oldApps/link/tile/tile.js | 48 --------- .../src/oldApps/publish/tile/tile.js | 51 ---------- pkg/interface/src/oldApps/soto/tile/tile.js | 33 ------- pkg/interface/src/reducers/chat-update.js | 22 ++++- pkg/interface/src/reducers/contact-update.js | 10 +- pkg/interface/src/reducers/group-update.js | 15 ++- pkg/interface/src/reducers/initial.js | 43 -------- pkg/interface/src/reducers/invite-update.js | 10 +- .../{apps/links => }/reducers/link-update.js | 0 .../links => }/reducers/listen-update.js | 0 pkg/interface/src/reducers/metadata-update.js | 58 ++++++----- .../src/reducers/permission-update.js | 15 ++- .../publish-response.js} | 27 ++--- .../primary.js => reducers/publish-update.js} | 71 +------------- .../src/reducers/{s3.js => s3-update.js} | 2 +- pkg/interface/src/store.js | 2 - pkg/interface/src/store/chat.js | 51 ++++++++++ pkg/interface/src/store/groups.js | 45 +++++++++ pkg/interface/src/store/links.js | 55 +++++++++++ pkg/interface/src/store/publish.js | 45 +++++++++ 48 files changed, 327 insertions(+), 1253 deletions(-) rename pkg/interface/src/{apps/publish/api.js => api/publish.js} (52%) rename pkg/interface/src/apps/chat/{ChatApp.js => app.js} (99%) delete mode 100644 pkg/interface/src/apps/chat/store.js rename pkg/interface/src/apps/dojo/{DojoApp.js => app.js} (100%) rename pkg/interface/src/apps/groups/{GroupsApp.js => app.js} (99%) delete mode 100644 pkg/interface/src/apps/groups/reducers/metadata-update.js delete mode 100644 pkg/interface/src/apps/groups/store.js rename pkg/interface/src/apps/links/{LinksApp.js => app.js} (99%) delete mode 100644 pkg/interface/src/apps/links/store.js rename pkg/interface/src/apps/publish/{PublishApp.js => app.js} (98%) delete mode 100644 pkg/interface/src/apps/publish/reducers/group.js delete mode 100644 pkg/interface/src/apps/publish/reducers/initial.js delete mode 100644 pkg/interface/src/apps/publish/reducers/invite.js delete mode 100644 pkg/interface/src/apps/publish/reducers/permission.js delete mode 100644 pkg/interface/src/apps/publish/store.js delete mode 100644 pkg/interface/src/oldApps/chat/tile/tile.js delete mode 100644 pkg/interface/src/oldApps/groups/tile/tile.js delete mode 100644 pkg/interface/src/oldApps/link-webext/background.js delete mode 100644 pkg/interface/src/oldApps/link-webext/browserAction/index.html delete mode 100644 pkg/interface/src/oldApps/link-webext/browserAction/script.js delete mode 100644 pkg/interface/src/oldApps/link-webext/browserAction/style.css delete mode 100644 pkg/interface/src/oldApps/link-webext/icons/icon.png delete mode 100644 pkg/interface/src/oldApps/link-webext/manifest.json delete mode 100644 pkg/interface/src/oldApps/link-webext/options/index.html delete mode 100644 pkg/interface/src/oldApps/link-webext/options/script.js delete mode 100644 pkg/interface/src/oldApps/link-webext/options/style.css delete mode 100644 pkg/interface/src/oldApps/link-webext/storage.js delete mode 100644 pkg/interface/src/oldApps/link/tile/tile.js delete mode 100644 pkg/interface/src/oldApps/publish/tile/tile.js delete mode 100644 pkg/interface/src/oldApps/soto/tile/tile.js delete mode 100644 pkg/interface/src/reducers/initial.js rename pkg/interface/src/{apps/links => }/reducers/link-update.js (100%) rename pkg/interface/src/{apps/links => }/reducers/listen-update.js (100%) rename pkg/interface/src/{apps/publish/reducers/response.js => reducers/publish-response.js} (93%) rename pkg/interface/src/{apps/publish/reducers/primary.js => reducers/publish-update.js} (83%) rename pkg/interface/src/reducers/{s3.js => s3-update.js} (98%) create mode 100644 pkg/interface/src/store/chat.js create mode 100644 pkg/interface/src/store/groups.js create mode 100644 pkg/interface/src/store/links.js create mode 100644 pkg/interface/src/store/publish.js diff --git a/pkg/interface/src/App.js b/pkg/interface/src/App.js index 397e9d86e..ad8543f60 100644 --- a/pkg/interface/src/App.js +++ b/pkg/interface/src/App.js @@ -6,12 +6,12 @@ import './css/fonts.css'; import { light } from '@tlon/indigo-react'; import LaunchApp from './apps/launch/app'; -import ChatApp from './apps/chat/ChatApp'; -import DojoApp from './apps/dojo/DojoApp'; +import ChatApp from './apps/chat/app'; +import DojoApp from './apps/dojo/app'; import StatusBar from './components/StatusBar'; -import GroupsApp from './apps/groups/GroupsApp'; -import LinksApp from './apps/links/LinksApp'; -import PublishApp from './apps/publish/PublishApp'; +import GroupsApp from './apps/groups/app'; +import LinksApp from './apps/links/app'; +import PublishApp from './apps/publish/app'; import Store from './store'; import Subscription from './subscription'; diff --git a/pkg/interface/src/apps/publish/api.js b/pkg/interface/src/api/publish.js similarity index 52% rename from pkg/interface/src/apps/publish/api.js rename to pkg/interface/src/api/publish.js index 4feea1548..453fa874e 100644 --- a/pkg/interface/src/apps/publish/api.js +++ b/pkg/interface/src/api/publish.js @@ -1,57 +1,9 @@ -import _ from 'lodash'; +import BaseApi from './base'; -export default class Api { - constructor(ship, channel, store) { - this.ship = ship; - this.channel = channel; - this.store = store; - this.bindPaths = []; - } - - bind(path, method, ship = this.ship, appl = 'publish', success, fail) { - this.bindPaths = _.uniq([...this.bindPaths, path]); - - this.channel.subscribe(ship, appl, path, - (err) => { - fail(err); - }, - (event) => { - success({ - data: event, - from: { - ship, - path - } - }); - }, - (err) => { - fail(err); - } - ); - } - - action(appl, mark, data) { - return new Promise((resolve, reject) => { - this.channel.poke(this.ship, appl, mark, data, - (json) => { - resolve(json); - }, - (err) => { - reject(err); - }); - }); - } - - // TODO add error handling - - handleErrors(response) { - if (!response.ok) -throw Error(response.status); - return response; - } +export default class PublishApi extends BaseApi { fetchNotebooks() { - fetch('/~publish/notebooks.json') + fetch('/publish-view/notebooks.json') .then(response => response.json()) .then((json) => { this.store.handleEvent({ @@ -62,7 +14,7 @@ throw Error(response.status); } fetchNotebook(host, book) { - fetch(`/~publish/${host}/${book}.json`) + fetch(`/publish-view/${host}/${book}.json`) .then(response => response.json()) .then((json) => { this.store.handleEvent({ @@ -75,7 +27,7 @@ throw Error(response.status); } fetchNote(host, book, note) { - fetch(`/~publish/${host}/${book}/${note}.json`) + fetch(`/publish-view/${host}/${book}/${note}.json`) .then(response => response.json()) .then((json) => { this.store.handleEvent({ @@ -89,7 +41,7 @@ throw Error(response.status); } fetchNotesPage(host, book, start, length) { - fetch(`/~publish/notes/${host}/${book}/${start}/${length}.json`) + fetch(`/publish-view/notes/${host}/${book}/${start}/${length}.json`) .then(response => response.json()) .then((json) => { this.store.handleEvent({ @@ -104,7 +56,7 @@ throw Error(response.status); } fetchCommentsPage(host, book, note, start, length) { - fetch(`/~publish/comments/${host}/${book}/${note}/${start}/${length}.json`) + fetch(`/publish-view/comments/${host}/${book}/${note}/${start}/${length}.json`) .then(response => response.json()) .then((json) => { this.store.handleEvent({ @@ -131,13 +83,5 @@ throw Error(response.status); } }); } - - setSelected(selected) { - this.store.handleEvent({ - type: 'local', - data: { - selected: selected - } - }); - } } + diff --git a/pkg/interface/src/apps/chat/ChatApp.js b/pkg/interface/src/apps/chat/app.js similarity index 99% rename from pkg/interface/src/apps/chat/ChatApp.js rename to pkg/interface/src/apps/chat/app.js index 26815650b..f55e98ae8 100644 --- a/pkg/interface/src/apps/chat/ChatApp.js +++ b/pkg/interface/src/apps/chat/app.js @@ -2,7 +2,7 @@ import React from 'react'; import { Route } from 'react-router-dom'; import Api from './api'; -import Store from './store'; +import ChatStore from '../../store/chat'; import Subscription from './subscription'; import './css/custom.css'; diff --git a/pkg/interface/src/apps/chat/store.js b/pkg/interface/src/apps/chat/store.js deleted file mode 100644 index 0e5dcec45..000000000 --- a/pkg/interface/src/apps/chat/store.js +++ /dev/null @@ -1,73 +0,0 @@ -import InitialReducer from '../../reducers/initial'; -import ContactUpdateReducer from '../../reducers/contact-update'; -import ChatUpdateReducer from '../../reducers/chat-update'; -import InviteUpdateReducer from '../../reducers/invite-update'; -import PermissionUpdateReducer from '../../reducers/permission-update'; -import MetadataReducer from '../../reducers/metadata-update'; -import LocalReducer from '../../reducers/local'; -import S3Reducer from '../../reducers/s3'; - -export default class Store { - constructor() { - this.state = this.initialState(); - - this.initialReducer = new InitialReducer(); - this.permissionUpdateReducer = new PermissionUpdateReducer(); - this.contactUpdateReducer = new ContactUpdateReducer(); - this.chatUpdateReducer = new ChatUpdateReducer(); - this.inviteUpdateReducer = new InviteUpdateReducer(); - this.metadataReducer = new MetadataReducer(); - this.localReducer = new LocalReducer(); - this.s3Reducer = new S3Reducer(); - this.setState = () => {}; - } - - initialState() { - return { - inbox: {}, - chatSynced: null, - contacts: {}, - permissions: {}, - invites: {}, - associations: { - chat: {}, - contacts: {} - }, - sidebarShown: true, - pendingMessages: new Map([]), - chatInitialized: false, - s3: {} - }; - } - - setStateHandler(setState) { - this.setState = setState; - } - - clear() { - this.handleEvent({ - data: { clear: true } - }); - } - - handleEvent(data) { - let json = data.data; - - if ('clear' in json && json.clear) { - this.setState(this.initialState()); - return; - } - - this.initialReducer.reduce(json, this.state); - this.permissionUpdateReducer.reduce(json, this.state); - this.contactUpdateReducer.reduce(json, this.state); - this.chatUpdateReducer.reduce(json, this.state); - this.inviteUpdateReducer.reduce(json, this.state); - this.metadataReducer.reduce(json, this.state); - this.localReducer.reduce(json, this.state); - this.s3Reducer.reduce(json, this.state); - - this.setState(this.state); - } -} - diff --git a/pkg/interface/src/apps/dojo/DojoApp.js b/pkg/interface/src/apps/dojo/app.js similarity index 100% rename from pkg/interface/src/apps/dojo/DojoApp.js rename to pkg/interface/src/apps/dojo/app.js diff --git a/pkg/interface/src/apps/groups/GroupsApp.js b/pkg/interface/src/apps/groups/app.js similarity index 99% rename from pkg/interface/src/apps/groups/GroupsApp.js rename to pkg/interface/src/apps/groups/app.js index 0eb16a433..1a1e5f707 100644 --- a/pkg/interface/src/apps/groups/GroupsApp.js +++ b/pkg/interface/src/apps/groups/app.js @@ -3,7 +3,7 @@ import { Route } from 'react-router-dom'; import Api from './api'; import Subscription from './subscription'; -import Store from './store'; +import GroupsStore from '../../store/groups'; import './css/custom.css'; @@ -17,7 +17,7 @@ import GroupDetail from './components/lib/group-detail'; export default class GroupsApp extends Component { constructor(props) { super(props); - this.store = new Store(); + this.store = new GroupsStore(); this.store.setStateHandler(this.setState.bind(this)); this.state = this.store.state; diff --git a/pkg/interface/src/apps/groups/reducers/metadata-update.js b/pkg/interface/src/apps/groups/reducers/metadata-update.js deleted file mode 100644 index d4d23e69b..000000000 --- a/pkg/interface/src/apps/groups/reducers/metadata-update.js +++ /dev/null @@ -1,71 +0,0 @@ -import _ from 'lodash'; - -export class MetadataReducer { - reduce(json, state) { - let data = _.get(json, 'metadata-update', false); - if (data) { - this.associations(data, state); - this.add(data, state); - this.update(data, state); - this.remove(data, state); - } - } - - associations(json, state) { - let data = _.get(json, 'associations', false); - if (data) { - let metadata = {}; - Object.keys(data).forEach((key) => { - let val = data[key]; - let groupPath = val['group-path']; - if (!(groupPath in metadata)) { - metadata[groupPath] = {}; - } - metadata[groupPath][key] = val; - }); - state.associations = metadata; - } - } - - add(json, state) { - let data = _.get(json, 'add', false); - if (data) { - let metadata = state.associations; - if (!(data['group-path'] in metadata)) { - metadata[data['group-path']] = {}; - } - metadata[data['group-path']] - [`${data["group-path"]}/${data["app-name"]}${data["app-path"]}`] = data; - - state.associations = metadata; - } - } - - update(json, state) { - let data = _.get(json, 'update-metadata', false); - if (data) { - let metadata = state.associations; - if (!(data["group-path"] in metadata)) { - metadata[data["group-path"]] = {}; - } - metadata[data["group-path"]][ - `${data["group-path"]}/${data["app-name"]}${data["app-path"]}` - ] = data; - - state.associations = metadata; - } - } - - remove(json, state) { - let data = _.get(json, 'remove', false); - if (data) { - let metadata = state.associations; - if (data['group-path'] in metadata) { - let path = - `${data['group-path']}/${data['app-name']}${data['app-path']}` - delete metadata[data["group-path"]][path]; - state.associations = metadata; - } - } - } -} diff --git a/pkg/interface/src/apps/groups/store.js b/pkg/interface/src/apps/groups/store.js deleted file mode 100644 index 9661e2752..000000000 --- a/pkg/interface/src/apps/groups/store.js +++ /dev/null @@ -1,66 +0,0 @@ -import InitialReducer from '../../reducers/initial'; -import ContactUpdateReducer from '../../reducers/contact-update'; -import GroupUpdateReducer from '../../reducers/group-update'; -import InviteUpdateReducer from '../../reducers/invite-update'; -import PermissionUpdateReducer from '../../reducers/permission-update'; -import { MetadataReducer } from './reducers/metadata-update'; -import LocalReducer from '../../reducers/local'; -import S3Reducer from '../../reducers/s3.js'; - -export default class Store { - constructor() { - this.state = this.initialState(); - - this.initialReducer = new InitialReducer(); - this.groupUpdateReducer = new GroupUpdateReducer(); - this.permissionUpdateReducer = new PermissionUpdateReducer(); - this.contactUpdateReducer = new ContactUpdateReducer(); - this.inviteUpdateReducer = new InviteUpdateReducer(); - this.metadataReducer = new MetadataReducer(); - this.s3Reducer = new S3Reducer(); - this.localReducer = new LocalReducer(); - this.setState = () => {}; - } - - initialState() { - return { - contacts: {}, - groups: {}, - associations: {}, - permissions: {}, - invites: {}, - s3: {} - }; - } - - clear() { - this.handleEvent({ - data: { clear: true } - }); - } - - setStateHandler(setState) { - this.setState = setState; - } - - handleEvent(data) { - const json = data.data; - - if ('clear' in json && json.clear) { - this.setState(this.initialState()); - return; - } - - console.log(json); - this.initialReducer.reduce(json, this.state); - this.groupUpdateReducer.reduce(json, this.state); - this.permissionUpdateReducer.reduce(json, this.state); - this.contactUpdateReducer.reduce(json, this.state); - this.inviteUpdateReducer.reduce(json, this.state); - this.metadataReducer.reduce(json, this.state); - this.s3Reducer.reduce(json, this.state); - this.localReducer.reduce(json, this.state); - - this.setState(this.state); - } -} diff --git a/pkg/interface/src/apps/links/LinksApp.js b/pkg/interface/src/apps/links/app.js similarity index 99% rename from pkg/interface/src/apps/links/LinksApp.js rename to pkg/interface/src/apps/links/app.js index 036797b75..a6adebf9b 100644 --- a/pkg/interface/src/apps/links/LinksApp.js +++ b/pkg/interface/src/apps/links/app.js @@ -4,7 +4,7 @@ import { Switch, Route } from 'react-router-dom'; import _ from 'lodash'; import Api from './api'; -import Store from './store'; +import LinksStore from '../../store/links'; import Subscription from './subscription'; import './css/custom.css'; @@ -21,7 +21,7 @@ import { makeRoutePath, amOwnerOfGroup, base64urlDecode } from '../../lib/util'; export class LinksApp extends Component { constructor(props) { super(props); - this.store = new Store(); + this.store = new LinksStore(); this.store.setStateHandler(this.setState.bind(this)); this.state = this.store.state; diff --git a/pkg/interface/src/apps/links/store.js b/pkg/interface/src/apps/links/store.js deleted file mode 100644 index 21e267012..000000000 --- a/pkg/interface/src/apps/links/store.js +++ /dev/null @@ -1,81 +0,0 @@ -import InitialReducer from '../../reducers/initial'; -import GroupUpdateReducer from '../../reducers/group-update'; -import ContactUpdateReducer from '../../reducers/contact-update'; -import PermissionUpdateReducer from '../../reducers/permission-update'; -import MetadataReducer from '../../reducers/metadata-update'; -import InviteUpdateReducer from '../../reducers/invite-update'; -import LinkUpdateReducer from './reducers/link-update'; -import ListenUpdateReducer from './reducers/listen-update'; -import LocalReducer from '../../reducers/local'; - -export default class Store { - constructor() { - this.state = this.initialState(); - - this.initialReducer = new InitialReducer(); - this.groupUpdateReducer = new GroupUpdateReducer(); - this.contactUpdateReducer = new ContactUpdateReducer(); - this.permissionUpdateReducer = new PermissionUpdateReducer(); - this.metadataReducer = new MetadataReducer(); - this.inviteUpdateReducer = new InviteUpdateReducer(); - this.localReducer = new LocalReducer(); - this.linkUpdateReducer = new LinkUpdateReducer(); - this.listenUpdateReducer = new ListenUpdateReducer(); - this.setState = () => {}; - } - - setStateHandler(setState) { - this.setState = setState; - } - - initialState() { - return { - contacts: {}, - groups: {}, - associations: { - link: {}, - contacts: {} - }, - invites: {}, - links: {}, - listening: new Set(), - comments: {}, - seen: {}, - permissions: {}, - sidebarShown: true - }; - } - - clear() { - this.handleEvent({ - data: { clear: true } - }); - } - - handleEvent(data) { - let json; - if (data.data) { - json = data.data; - } else { - json = data; - } - - if ('clear' in json && json.clear) { - this.setState(this.initialState()); - return; - } - - console.log('event', json); - this.initialReducer.reduce(json, this.state); - this.groupUpdateReducer.reduce(json, this.state); - this.contactUpdateReducer.reduce(json, this.state); - this.permissionUpdateReducer.reduce(json, this.state); - this.metadataReducer.reduce(json, this.state); - this.inviteUpdateReducer.reduce(json, this.state); - this.localReducer.reduce(json, this.state); - this.linkUpdateReducer.reduce(json, this.state); - this.listenUpdateReducer.reduce(json, this.state); - - this.setState(this.state); - } -} diff --git a/pkg/interface/src/apps/publish/PublishApp.js b/pkg/interface/src/apps/publish/app.js similarity index 98% rename from pkg/interface/src/apps/publish/PublishApp.js rename to pkg/interface/src/apps/publish/app.js index 73acd0cb5..ecc6c07db 100644 --- a/pkg/interface/src/apps/publish/PublishApp.js +++ b/pkg/interface/src/apps/publish/app.js @@ -4,8 +4,8 @@ import _ from 'lodash'; import './css/custom.css'; -import Api from './api'; -import Store from './store'; +import PublishApi from '../../api/publish'; +import PublishStore from '../../store/publish'; import Subscription from './subscription'; import { Skeleton } from './components/skeleton'; @@ -37,7 +37,7 @@ export default class PublishApp extends React.Component { this.store.clear(); const channel = new this.props.channel(); - this.api = new Api(this.props.ship, channel, this.store); + this.api = new PublishApi(this.props.ship, channel, this.store); this.subscription = new Subscription(this.store, this.api, channel); this.subscription.start(); diff --git a/pkg/interface/src/apps/publish/reducers/group.js b/pkg/interface/src/apps/publish/reducers/group.js deleted file mode 100644 index a8fa14d2a..000000000 --- a/pkg/interface/src/apps/publish/reducers/group.js +++ /dev/null @@ -1,68 +0,0 @@ -import _ from "lodash"; - -export class GroupReducer { - reduce(json, state) { - let data = _.get(json, "group-initial", false); - if (data) { - for (let group in data) { - state.groups[group] = new Set(data[group]); - } - } - - data = _.get(json, "group-update", false); - if (data) { - this.add(data, state); - this.remove(data, state); - this.bundle(data, state); - this.unbundle(data, state); - this.keys(data, state); - this.path(data, state); - } - } - - add(json, state) { - let data = _.get(json, "add", false); - if (data) { - for (let member of data.members) { - state.groups[data.path].add(member); - } - } - } - - remove(json, state) { - let data = _.get(json, "remove", false); - if (data) { - for (let member of data.members) { - state.groups[data.path].delete(member); - } - } - } - - bundle(json, state) { - let data = _.get(json, "bundle", false); - if (data) { - state.groups[data.path] = new Set(); - } - } - - unbundle(json, state) { - let data = _.get(json, "unbundle", false); - if (data) { - delete state.groups[data.path]; - } - } - - keys(json, state) { - let data = _.get(json, "keys", false); - if (data) { - state.groupKeys = new Set(data.keys); - } - } - - path(json, state) { - let data = _.get(json, "path", false); - if (data) { - state.groups[data.path] = new Set([data.members]); - } - } - } \ No newline at end of file diff --git a/pkg/interface/src/apps/publish/reducers/initial.js b/pkg/interface/src/apps/publish/reducers/initial.js deleted file mode 100644 index 4264836ac..000000000 --- a/pkg/interface/src/apps/publish/reducers/initial.js +++ /dev/null @@ -1,7 +0,0 @@ -import _ from 'lodash'; - -export class InitialReducer { - reduce(json, state) { - state.notebooks = json.notebooks || null; - } -} diff --git a/pkg/interface/src/apps/publish/reducers/invite.js b/pkg/interface/src/apps/publish/reducers/invite.js deleted file mode 100644 index cedff5afa..000000000 --- a/pkg/interface/src/apps/publish/reducers/invite.js +++ /dev/null @@ -1,58 +0,0 @@ -import _ from 'lodash'; - -export class InviteReducer { - reduce(json, state) { - let initial = _.get(json, 'invite-initial', false); - if (initial) { - this.initial(initial, state); - } - let update = _.get(json, 'invite-update', false); - if (update) { - this.create(update, state); - this.delete(update, state); - this.invite(update, state); - this.accepted(update, state); - this.decline(update, state); - } - } - - initial(json, state) { - state.invites = json;; - } - - create(json, state) { - let data = _.get(json, 'create', false); - if (data) { - state.invites[data.path] = {}; - } - } - - delete(json, state) { - let data = _.get(json, 'delete', false); - if (data) { - delete state.invites[data.path]; - } - } - - invite(json, state) { - let data = _.get(json, 'invite', false); - if (data) { - state.invites[data.path][data.uid] = data.invite; - } - } - - accepted(json, state) { - let data = _.get(json, 'accepted', false); - if (data) { - delete state.invites[data.path][data.uid]; - } - } - - decline(json, state) { - let data = _.get(json, 'decline', false); - if (data) { - delete state.invites[data.path][data.uid]; - } - } -} - diff --git a/pkg/interface/src/apps/publish/reducers/permission.js b/pkg/interface/src/apps/publish/reducers/permission.js deleted file mode 100644 index 80af6f4c5..000000000 --- a/pkg/interface/src/apps/publish/reducers/permission.js +++ /dev/null @@ -1,58 +0,0 @@ -import _ from 'lodash'; - -export class PermissionReducer { - reduce(json, state) { - let data = _.get(json, 'permission-initial', false); - if (data) { - for (let perm in data) { - state.permissions[perm] = { - who: new Set(data[perm].who), - kind: data[perm].kind - } - } - } - data = _.get(json, 'permission-update', false); - if (data) { - this.create(data, state); - this.delete(data, state); - this.add(data, state); - this.remove(data, state); - } - } - - create(json, state) { - let data = _.get(json, 'create', false); - if (data) { - state.permissions[data.path] = { - kind: data.kind, - who: new Set(data.who) - }; - } - } - - delete(json, state) { - let data = _.get(json, 'delete', false); - if (data) { - delete state.permissions[data.path]; - } - } - - add(json, state) { - let data = _.get(json, 'add', false); - if (data) { - for (let member of data.who) { - state.permissions[data.path].who.add(member); - } - } - } - - remove(json, state) { - let data = _.get(json, 'remove', false); - if (data) { - for (let member of data.who) { - state.permissions[data.path].who.delete(member); - } - } - } -} - diff --git a/pkg/interface/src/apps/publish/store.js b/pkg/interface/src/apps/publish/store.js deleted file mode 100644 index aed055666..000000000 --- a/pkg/interface/src/apps/publish/store.js +++ /dev/null @@ -1,67 +0,0 @@ -import { InitialReducer } from './reducers/initial'; -import { PrimaryReducer } from './reducers/primary'; -import { ResponseReducer } from './reducers/response'; -import { GroupReducer } from './reducers/group'; -import { InviteReducer } from './reducers/invite'; -import { PermissionReducer } from './reducers/permission'; -import MetadataReducer from '../../reducers/metadata-update'; - -export default class Store { - constructor() { - this.state = this.initialState(); - - this.initialReducer = new InitialReducer(); - this.primaryReducer = new PrimaryReducer(); - this.responseReducer = new ResponseReducer(); - this.groupReducer = new GroupReducer(); - this.inviteReducer = new InviteReducer(); - this.permissionReducer = new PermissionReducer(); - this.metadataReducer = new MetadataReducer(); - this.setState = () => {}; - } - - initialState() { - return { - notebooks: {}, - groups: {}, - contacts: {}, - associations: { - contacts: {} - }, - permissions: {}, - invites: {}, - sidebarShown: true - }; - } - - clear() { - this.handleEvent({ - data: { clear: true } - }); - } - - setStateHandler(setState) { - this.setState = setState; - } - - handleEvent(evt) { - if (evt.data && 'clear' in evt.data && evt.data.clear) { - this.setState(this.initialState()); - return; - } - - if (evt.from && evt.from.path === '/all') { - this.groupReducer.reduce(evt.data, this.state); - this.permissionReducer.reduce(evt.data, this.state); - } else if (evt.from && evt.from.path === '/app-name/contacts') { - this.metadataReducer.reduce(evt.data, this.state); - } else if (evt.from && evt.from.path === '/primary') { - this.primaryReducer.reduce(evt.data, this.state); - this.inviteReducer.reduce(evt.data, this.state); - } else if (evt.type) { - this.responseReducer.reduce(evt, this.state); - } - this.setState(this.state); - } -} - diff --git a/pkg/interface/src/oldApps/chat/tile/tile.js b/pkg/interface/src/oldApps/chat/tile/tile.js deleted file mode 100644 index 7452458d5..000000000 --- a/pkg/interface/src/oldApps/chat/tile/tile.js +++ /dev/null @@ -1,60 +0,0 @@ -import React, { Component } from 'react'; -import classnames from 'classnames'; -import _ from 'lodash'; - - -export default class ChatTile extends Component { - - render() { - const { props } = this; - - let data = _.get(props.data, 'chat-configs', false); - - let inviteNum = 0; - let msgNum = 0; - - if (data) { - Object.keys(data).forEach((conf) => { - console.log(conf); - msgNum = msgNum + data[conf].length - data[conf].read; - }); - } - - let notificationsNum = inviteNum + msgNum; - - let numNotificationsElem = - notificationsNum > 0 ? ( -

- {notificationsNum > 99 ? "99+" : notificationsNum} -

- ) : ( -
- ); - - return ( -
- -

Messaging

- - {numNotificationsElem} -
-
- ); - } - -} - -window['chat-viewTile'] = ChatTile; diff --git a/pkg/interface/src/oldApps/groups/tile/tile.js b/pkg/interface/src/oldApps/groups/tile/tile.js deleted file mode 100644 index 7bc8fd0b2..000000000 --- a/pkg/interface/src/oldApps/groups/tile/tile.js +++ /dev/null @@ -1,58 +0,0 @@ -import React, { Component } from 'react'; -import classnames from 'classnames'; -import _ from 'lodash'; - - -export default class ContactTile extends Component { - - render() { - const { props } = this; - - let data = _.get(props.data, "invites", false); - let inviteNum = 0; - - if (data && "/contacts" in data) { - inviteNum = Object.keys(data["/contacts"]).length; - } - - let numNotificationsElem = - inviteNum > 0 ? ( -

- {inviteNum > 99 ? "99+" : inviteNum} -

- ) : ( -
- ); - - return ( -
- -

- Groups -

- - {numNotificationsElem} -
-
- ); - } - -} - -window['contact-viewTile'] = ContactTile; diff --git a/pkg/interface/src/oldApps/link-webext/background.js b/pkg/interface/src/oldApps/link-webext/background.js deleted file mode 100644 index bef42b9d0..000000000 --- a/pkg/interface/src/oldApps/link-webext/background.js +++ /dev/null @@ -1,92 +0,0 @@ - -const attemptPost = (endpoint, path, data) => { - console.log('sending', data, JSON.stringify(data)); - return new Promise((resolve, reject) => { - fetch(`http://${endpoint}/~link${path}`, { - method: 'POST', - credentials: 'include', - body: JSON.stringify(data) - }) - .then(response => { - console.log('resp', response.status); - resolve(response.status === 200); - }) - .catch(error => { - console.error('post failed', error); - resolve(false); - }); - }); -} - -const attemptGet = (endpoint, path, data) => { - return new Promise((resolve, reject) => { - fetch(`http://${endpoint}/~link{path}`, { - method: 'GET', - credentials: 'include', - body: JSON.stringify(data) - }) - .then(response => { - console.log('get response'); - console.log('response', response); - resolve(true); - }) - .catch(error => { - console.log('fetch error', error); - resolve(false); - }); - }); -} - -const saveUrl = (endpoint, title, url) => { - return attemptPost(endpoint, '/add/private', {title, url}); -} - -const openOptions = () => { - browser.tabs.create({ - url: browser.runtime.getURL('options/index.html') - }); -} - -const openLogin = (endpoint) => { - browser.tabs.create({ - url: `http://${endpoint}/~/login` - }); -} - -const doSave = async () => { - console.log('gonna do save!'); - // if no endpoint, refer to options page - const endpoint = await getEndpoint(); - console.log('endpoint', endpoint); - if (endpoint === null) { - return openOptions(); - } - - const tab = (await browser.tabs.query({currentWindow: true, active: true}))[0]; - //TODO figure out if we're viewing urbit page, turn into arvo:// url? - const success = await saveUrl(endpoint, tab.title, tab.url); - console.log('success', success); - if (!success) { - console.log('failed, opening login'); - openLogin(endpoint); - } else { - console.log('success!'); - } -} - - -// perform save action when extension button is clicked -//TODO want to do a pop-up instead of on-click action here latern -// -browser.browserAction.onClicked.addListener(doSave); - -// open settings page on-install, user will need to set endpoint -// -browser.runtime.onInstalled.addListener(async ({ reason, temporary }) => { - // if (temporary) return; // skip during development - switch (reason) { - case "install": - browser.runtime.openOptionsPage(); - break; - } -}); diff --git a/pkg/interface/src/oldApps/link-webext/browserAction/index.html b/pkg/interface/src/oldApps/link-webext/browserAction/index.html deleted file mode 100644 index fc7571809..000000000 --- a/pkg/interface/src/oldApps/link-webext/browserAction/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - -

My browser action

- - - diff --git a/pkg/interface/src/oldApps/link-webext/browserAction/script.js b/pkg/interface/src/oldApps/link-webext/browserAction/script.js deleted file mode 100644 index 80333ffad..000000000 --- a/pkg/interface/src/oldApps/link-webext/browserAction/script.js +++ /dev/null @@ -1 +0,0 @@ -console.log('script.js firing'); \ No newline at end of file diff --git a/pkg/interface/src/oldApps/link-webext/browserAction/style.css b/pkg/interface/src/oldApps/link-webext/browserAction/style.css deleted file mode 100644 index 001d5c5dc..000000000 --- a/pkg/interface/src/oldApps/link-webext/browserAction/style.css +++ /dev/null @@ -1,3 +0,0 @@ -h1 { - font-style: italic; -} diff --git a/pkg/interface/src/oldApps/link-webext/icons/icon.png b/pkg/interface/src/oldApps/link-webext/icons/icon.png deleted file mode 100644 index a5dcb632da606a8d3da192bd188c2b7bd814f8c1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 979 zcmV;^11$WBP)004R= z004l4008;_004mL004C`008P>0026e000+nl3&F}00009a7bBm000XU000XU0RWnu z7ytkRSxH1eRCwCenOjIyK^VtH%ewra1 zT%nm}TDinE9x#ZDpVlOVg8suWT{KaN4b5P+T;>}tH3^~MCuze@xd82N$LLm(U>*O3 zbHeWqG#hW2H4|VRKTNd(TtlOYG4q*V6+c9SBECX501^RK@or8kb-sp11K-VmNUH+6 z6yX{+?wGF#*8lo)WdRk2wLl=js(?;qyhex0su&zM!A%acl`NK#!CLlENRa}%gnb-j z##}%!_$XB@B~f7M9(9lRDnN+gLqnQ0vQO|j9(_@q%$6sWj5I$!sC^W!N^PB-* zbB`opog|TfaUs4mD16S=_`wg+#{3r@IC0Y&jkDO7&FW|SifTj@UznUd+UA!OYAFU5E zzia7ZkY3722?3ug+m7^GkF0@AMm#>V+@g$ZivrRFQGsA7zAtUylh`ECA*}! z_ng5tWZxsZq=6#8SkU3O`K(jIujI1y6Dhq*WMx>>yJD-z*8p+~y&fi;p5) diff --git a/pkg/interface/src/oldApps/link-webext/manifest.json b/pkg/interface/src/oldApps/link-webext/manifest.json deleted file mode 100644 index bdf30a2ba..000000000 --- a/pkg/interface/src/oldApps/link-webext/manifest.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "manifest_version": 2, - "name": "link", - "description": "Urbit Link", - "version": "0.0.0", - "icons": { - "64": "icons/icon.png" - }, - "browser_action": { - "default_icon": { - "64": "icons/icon.png" - }, - "todo__default_popup": "browserAction/index.html", - "default_title": "link" - }, - "background": { - "scripts": [ - "background.js", - "storage.js" - ] - }, - "options_ui": { - "page": "options/index.html" - }, - "web_accessible_resources": [ - "src/options/options.html" - ], - - "permissions": [ - "storage", // storing config - "activeTab" // viewing current page url & title - ], - - "applications": { - "gecko": { - "id": "link-webext@tlon.io" - } - } -} \ No newline at end of file diff --git a/pkg/interface/src/oldApps/link-webext/options/index.html b/pkg/interface/src/oldApps/link-webext/options/index.html deleted file mode 100644 index 91986a3ae..000000000 --- a/pkg/interface/src/oldApps/link-webext/options/index.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - -
- - - -
- - - - - - diff --git a/pkg/interface/src/oldApps/link-webext/options/script.js b/pkg/interface/src/oldApps/link-webext/options/script.js deleted file mode 100644 index 62cf914dc..000000000 --- a/pkg/interface/src/oldApps/link-webext/options/script.js +++ /dev/null @@ -1,21 +0,0 @@ - -function storeOptions(e) { - e.preventDefault(); - - // clean up endpoint address and store it - let endpoint = document.querySelector("#endpoint").value - .replace(/^.*:\/\//, '') // strip protocol - .replace(/\/+$/, ''); // strip trailing slashes - setEndpoint(endpoint); -} - -async function restoreOptions() { - - const endpoint = await getEndpoint(); - console.log('prefilling with', endpoint); - - document.querySelector("#endpoint").value = endpoint; -} - -document.addEventListener("DOMContentLoaded", restoreOptions); -document.querySelector("form").addEventListener("submit", storeOptions); \ No newline at end of file diff --git a/pkg/interface/src/oldApps/link-webext/options/style.css b/pkg/interface/src/oldApps/link-webext/options/style.css deleted file mode 100644 index 001d5c5dc..000000000 --- a/pkg/interface/src/oldApps/link-webext/options/style.css +++ /dev/null @@ -1,3 +0,0 @@ -h1 { - font-style: italic; -} diff --git a/pkg/interface/src/oldApps/link-webext/storage.js b/pkg/interface/src/oldApps/link-webext/storage.js deleted file mode 100644 index 19d9db91b..000000000 --- a/pkg/interface/src/oldApps/link-webext/storage.js +++ /dev/null @@ -1,20 +0,0 @@ -// use synced storage if supported, fall back to local -const storage = browser.storage.sync || browser.storage.local; - -const setEndpoint = (endpoint) => { - return storage.set({endpoint}); -} - -const getEndpoint = () => { - return new Promise((resolve, reject) => { - storage.get("endpoint").then((res) => { - if (res && res.endpoint) { - resolve(res.endpoint); - } else { - resolve(null); - } - }, (err) => { - resolve(null); - }); - }); -} diff --git a/pkg/interface/src/oldApps/link/tile/tile.js b/pkg/interface/src/oldApps/link/tile/tile.js deleted file mode 100644 index 784bae727..000000000 --- a/pkg/interface/src/oldApps/link/tile/tile.js +++ /dev/null @@ -1,48 +0,0 @@ -import React, { Component } from 'react'; -import classnames from 'classnames'; -import _ from 'lodash'; - - -export default class LinkTile extends Component { - - render() { - const unseenCount = this.props.data.unseen || 0; - - let displayUnseen = unseenCount <= 0 - ? null - :

- {unseenCount > 99 ? "99+" : unseenCount} -

; - - return ( - - ); - } - -} - -window['link-viewTile'] = LinkTile; diff --git a/pkg/interface/src/oldApps/publish/tile/tile.js b/pkg/interface/src/oldApps/publish/tile/tile.js deleted file mode 100644 index 7b1e23bf9..000000000 --- a/pkg/interface/src/oldApps/publish/tile/tile.js +++ /dev/null @@ -1,51 +0,0 @@ -import React, { Component } from 'react' -import classnames from 'classnames'; - - -export default class PublishTile extends Component { - constructor(props){ - super(props); - console.log("publish-tile", this.props); - } - - - render(){ - - let notificationsNum = this.props.data.notifications; - - if (notificationsNum === 0) { - notificationsNum = ""; - } - else if (notificationsNum > 99) { - notificationsNum = "99+"; - } - else if (isNaN(notificationsNum)) { - notificationsNum = ""; - } - - return ( - - ); - } -} - -window.publishTile = PublishTile; diff --git a/pkg/interface/src/oldApps/soto/tile/tile.js b/pkg/interface/src/oldApps/soto/tile/tile.js deleted file mode 100644 index c98269a94..000000000 --- a/pkg/interface/src/oldApps/soto/tile/tile.js +++ /dev/null @@ -1,33 +0,0 @@ -import React, { Component } from 'react'; -import classnames from 'classnames'; -import _ from 'lodash'; - - -export default class sotoTile extends Component { - - render() { - return ( - - ); - } - -} - -window.sotoTile = sotoTile; diff --git a/pkg/interface/src/reducers/chat-update.js b/pkg/interface/src/reducers/chat-update.js index 2992a7919..fae8ae22e 100644 --- a/pkg/interface/src/reducers/chat-update.js +++ b/pkg/interface/src/reducers/chat-update.js @@ -1,9 +1,10 @@ import _ from 'lodash'; -export default class ChatUpdateReducer { +export default class ChatReducer { reduce(json, state) { - const data = _.get(json, 'chat-update', false); + let data = _.get(json, 'chat-update', false); if (data) { + this.initial(data, state); this.pending(data, state); this.message(data, state); this.messages(data, state); @@ -11,6 +12,23 @@ export default class ChatUpdateReducer { this.create(data, state); this.delete(data, state); } + + data = _.get(json, 'chat-hook-update', false); + if (data) { + this.hook(data, state); + } + } + + initial(json, state) { + const data = _.get(json, 'initial', false); + if (data) { + state.inbox = data; + state.chatInitialized = true; + } + } + + hook(json, state) { + state.chatSynced = data; } message(json, state) { diff --git a/pkg/interface/src/reducers/contact-update.js b/pkg/interface/src/reducers/contact-update.js index 72a36ced7..56d4fda75 100644 --- a/pkg/interface/src/reducers/contact-update.js +++ b/pkg/interface/src/reducers/contact-update.js @@ -1,9 +1,10 @@ import _ from 'lodash'; -export default class ContactUpdateReducer { +export default class ContactReducer { reduce(json, state) { const data = _.get(json, 'contact-update', false); if (data) { + this.initial(data, state); this.create(data, state); this.delete(data, state); this.add(data, state); @@ -12,6 +13,13 @@ export default class ContactUpdateReducer { } } + initial(json, state) { + const data = _.get(json, 'initial', false); + if (data) { + state.contacts = data; + } + } + create(json, state) { const data = _.get(json, 'create', false); if (data) { diff --git a/pkg/interface/src/reducers/group-update.js b/pkg/interface/src/reducers/group-update.js index 4784641f2..f9bcb1321 100644 --- a/pkg/interface/src/reducers/group-update.js +++ b/pkg/interface/src/reducers/group-update.js @@ -1,9 +1,11 @@ import _ from 'lodash'; -export default class GroupUpdateReducer { +export default class GroupReducer { + reduce(json, state) { - const data = _.get(json, 'group-update', false); + const data = _.get(json, "group-update", false); if (data) { + this.initial(data, state); this.add(data, state); this.remove(data, state); this.bundle(data, state); @@ -13,6 +15,15 @@ export default class GroupUpdateReducer { } } + initial(json, state) { + const data = _.get(json, 'initial', false); + if (data) { + for (let group in data) { + state.groups[group] = new Set(data[group]); + } + } + } + add(json, state) { const data = _.get(json, 'add', false); if (data) { diff --git a/pkg/interface/src/reducers/initial.js b/pkg/interface/src/reducers/initial.js deleted file mode 100644 index 1962c683f..000000000 --- a/pkg/interface/src/reducers/initial.js +++ /dev/null @@ -1,43 +0,0 @@ -import _ from 'lodash'; - -export default class InitialReducer { - reduce(json, state) { - let data = _.get(json, 'chat-initial', false); - if (data) { - state.inbox = data; - state.chatInitialized = true; - } - - data = _.get(json, 'permission-initial', false); - if (data) { - for (const perm in data) { - state.permissions[perm] = { - who: new Set(data[perm].who), - kind: data[perm].kind - }; - } - } - - data = _.get(json, 'group-initial', false); - if (data) { - for (const group in data) { - state.groups[group] = new Set(data[group]); - } - } - - data = _.get(json, 'invite-initial', false); - if (data) { - state.invites = data; - } - - data = _.get(json, 'contact-initial', false); - if (data) { - state.contacts = data; - } - - data = _.get(json, 'chat-hook-update', false); - if (data) { - state.chatSynced = data; - } - } -} diff --git a/pkg/interface/src/reducers/invite-update.js b/pkg/interface/src/reducers/invite-update.js index 34bd42c32..fb10d2b55 100644 --- a/pkg/interface/src/reducers/invite-update.js +++ b/pkg/interface/src/reducers/invite-update.js @@ -1,9 +1,10 @@ import _ from 'lodash'; -export default class InviteUpdateReducer { +export default class InviteReducer { reduce(json, state) { const data = _.get(json, 'invite-update', false); if (data) { + this.initial(data, state); this.create(data, state); this.delete(data, state); this.invite(data, state); @@ -12,6 +13,13 @@ export default class InviteUpdateReducer { } } + initial(json, state) { + const data = _.get(json, 'initial', false); + if (data) { + state.invites = data; + } + } + create(json, state) { const data = _.get(json, 'create', false); if (data) { diff --git a/pkg/interface/src/apps/links/reducers/link-update.js b/pkg/interface/src/reducers/link-update.js similarity index 100% rename from pkg/interface/src/apps/links/reducers/link-update.js rename to pkg/interface/src/reducers/link-update.js diff --git a/pkg/interface/src/apps/links/reducers/listen-update.js b/pkg/interface/src/reducers/listen-update.js similarity index 100% rename from pkg/interface/src/apps/links/reducers/listen-update.js rename to pkg/interface/src/reducers/listen-update.js diff --git a/pkg/interface/src/reducers/metadata-update.js b/pkg/interface/src/reducers/metadata-update.js index e2ffd38c5..a6bd20ce8 100644 --- a/pkg/interface/src/reducers/metadata-update.js +++ b/pkg/interface/src/reducers/metadata-update.js @@ -2,7 +2,7 @@ import _ from 'lodash'; export default class MetadataReducer { reduce(json, state) { - const data = _.get(json, 'metadata-update', false); + let data = _.get(json, 'metadata-update', false); if (data) { this.associations(data, state); this.add(data, state); @@ -12,54 +12,60 @@ export default class MetadataReducer { } associations(json, state) { - const data = _.get(json, 'associations', false); + let data = _.get(json, 'associations', false); if (data) { - const metadata = state.associations; - Object.keys(data).map((channel) => { - const channelObj = data[channel]; - const app = data[channel]['app-name']; - if (!(app in metadata)) { - metadata[app] = {}; + let metadata = {}; + Object.keys(data).forEach((key) => { + let val = data[key]; + let groupPath = val['group-path']; + if (!(groupPath in metadata)) { + metadata[groupPath] = {}; } - metadata[app][channelObj['app-path']] = channelObj; + metadata[groupPath][key] = val; }); state.associations = metadata; } } add(json, state) { - const data = _.get(json, 'add', false); + let data = _.get(json, 'add', false); if (data) { - const metadata = state.associations; - const app = data['app-name']; - if (!(app in metadata)) { - metadata[app] = {}; + let metadata = state.associations; + if (!(data['group-path'] in metadata)) { + metadata[data['group-path']] = {}; } - metadata[app][data['app-path']] = data; + metadata[data['group-path']] + [`${data["group-path"]}/${data["app-name"]}${data["app-path"]}`] = data; + state.associations = metadata; } } update(json, state) { - const data = _.get(json, 'update-metadata', false); + let data = _.get(json, 'update-metadata', false); if (data) { - const metadata = state.associations; - const app = data['app-name']; - metadata[app][data['app-path']] = data; + let metadata = state.associations; + if (!(data["group-path"] in metadata)) { + metadata[data["group-path"]] = {}; + } + metadata[data["group-path"]][ + `${data["group-path"]}/${data["app-name"]}${data["app-path"]}` + ] = data; + state.associations = metadata; } } remove(json, state) { - const data = _.get(json, 'remove', false); + let data = _.get(json, 'remove', false); if (data) { - const metadata = state.associations; - const app = data['app-name']; - if (!(app in metadata)) { - return false; + let metadata = state.associations; + if (data['group-path'] in metadata) { + let path = + `${data['group-path']}/${data['app-name']}${data['app-path']}` + delete metadata[data["group-path"]][path]; + state.associations = metadata; } - delete metadata[app][data['app-path']]; - state.associations = metadata; } } } diff --git a/pkg/interface/src/reducers/permission-update.js b/pkg/interface/src/reducers/permission-update.js index 382b30a5c..929ee9dfd 100644 --- a/pkg/interface/src/reducers/permission-update.js +++ b/pkg/interface/src/reducers/permission-update.js @@ -1,9 +1,10 @@ import _ from 'lodash'; -export default class PermissionUpdateReducer { +export default class PermissionReducer { reduce(json, state) { const data = _.get(json, 'permission-update', false); if (data) { + this.initial(data, state); this.create(data, state); this.delete(data, state); this.add(data, state); @@ -11,6 +12,18 @@ export default class PermissionUpdateReducer { } } + initial(json, state) { + const data = _.get(json, 'initial', false); + if (data) { + for (const perm in data) { + state.permissions[perm] = { + who: new Set(data[perm].who), + kind: data[perm].kind + }; + } + } + } + create(json, state) { const data = _.get(json, 'create', false); if (data) { diff --git a/pkg/interface/src/apps/publish/reducers/response.js b/pkg/interface/src/reducers/publish-response.js similarity index 93% rename from pkg/interface/src/apps/publish/reducers/response.js rename to pkg/interface/src/reducers/publish-response.js index 62711ab89..d4cd66f02 100644 --- a/pkg/interface/src/apps/publish/reducers/response.js +++ b/pkg/interface/src/reducers/publish-response.js @@ -1,26 +1,24 @@ import _ from 'lodash'; -export class ResponseReducer { +export default class PublishResponseReducer { reduce(json, state) { - switch(json.type) { + const data = _.get(json, 'publish-response', false); + if (!data) { return; } + switch(data.type) { case "notebooks": - this.handleNotebooks(json, state); + this.handleNotebooks(data, state); break; case "notebook": - this.handleNotebook(json, state); + this.handleNotebook(data, state); break; case "note": - this.handleNote(json, state); + this.handleNote(data, state); break; case "notes-page": - this.handleNotesPage(json, state); + this.handleNotesPage(data, state); break; case "comments-page": - this.handleCommentsPage(json, state); - break; - case "local": - this.sidebarToggle(json, state); - this.setSelected(json, state); + this.handleCommentsPage(data, state); break; default: break; @@ -204,11 +202,4 @@ export class ResponseReducer { } } - setSelected(json, state) { - let data = _.has(json.data, 'selected', false); - if (data) { - state.selectedGroups = json.data.selected; - } - } - } diff --git a/pkg/interface/src/apps/publish/reducers/primary.js b/pkg/interface/src/reducers/publish-update.js similarity index 83% rename from pkg/interface/src/apps/publish/reducers/primary.js rename to pkg/interface/src/reducers/publish-update.js index 796d46ceb..7d0d96301 100644 --- a/pkg/interface/src/apps/publish/reducers/primary.js +++ b/pkg/interface/src/reducers/publish-update.js @@ -1,9 +1,9 @@ import _ from 'lodash'; -export class PrimaryReducer { - reduce(json, state){ +export default class PublishUpdateReducer { + reduce(preJson, state){ + let json = _.get(preJson, "publish-update", false); switch(Object.keys(json)[0]){ - //publish actions case "add-book": this.addBook(json["add-book"], state); break; @@ -34,12 +34,6 @@ export class PrimaryReducer { case "read": this.read(json["read"], state); break; - // contacts actions - case "contact-initial": - this.contactInitial(json["contact-initial"], state); - break; - case "contact-update": - this.contactUpdate(json["contact-update"], state); default: break; } @@ -260,63 +254,4 @@ export class PrimaryReducer { } } - contactInitial(json, state) { - state.contacts = json; - } - - contactUpdate(json, state) { - this.createContact(json, state); - this.deleteContact(json, state); - this.addContact(json, state); - this.removeContact(json, state); - this.editContact(json, state); - } - - createContact(json, state) { - let data = _.get(json, "create", false); - if (data) { - state.contacts[data.path] = {}; - } - } - - deleteContact(json, state) { - let data = _.get(json, "delete", false); - if (data) { - delete state.contacts[data.path]; - } - } - - addContact(json, state) { - let data = _.get(json, "add", false); - if (data && data.path in state.contacts) { - state.contacts[data.path][data.ship] = data.contact; - } - } - - removeContact(json, state) { - let data = _.get(json, "remove", false); - if ( - data && - data.path in state.contacts && - data.ship in state.contacts[data.path] - ) { - delete state.contacts[data.path][data.ship]; - } - } - - editContact(json, state) { - let data = _.get(json, "edit", false); - if ( - data && - data.path in state.contacts && - data.ship in state.contacts[data.path] - ) { - let edit = Object.keys(data["edit-field"]); - if (edit.length !== 1) { - return; - } - state.contacts[data.path][data.ship][edit[0]] = - data["edit-field"][edit[0]]; - } - } } diff --git a/pkg/interface/src/reducers/s3.js b/pkg/interface/src/reducers/s3-update.js similarity index 98% rename from pkg/interface/src/reducers/s3.js rename to pkg/interface/src/reducers/s3-update.js index f710d643e..47c397e51 100644 --- a/pkg/interface/src/reducers/s3.js +++ b/pkg/interface/src/reducers/s3-update.js @@ -1,6 +1,6 @@ import _ from 'lodash'; -export default class S3Reducer { +export default class S3Reducer{ reduce(json, state) { const data = _.get(json, 's3-update', false); if (data) { diff --git a/pkg/interface/src/store.js b/pkg/interface/src/store.js index fffc844c4..d141da9ad 100644 --- a/pkg/interface/src/store.js +++ b/pkg/interface/src/store.js @@ -1,4 +1,3 @@ -import InitialReducer from './reducers/initial'; import InviteUpdateReducer from './reducers/invite-update'; import MetadataReducer from './reducers/metadata-update'; import LocalReducer from './reducers/local'; @@ -27,7 +26,6 @@ export default class Store { handleEvent(data) { let json = data.data; - this.initialReducer.reduce(json, this.state); this.inviteUpdateReducer.reduce(json, this.state); this.metadataReducer.reduce(json, this.state); this.localReducer.reduce(json, this.state); diff --git a/pkg/interface/src/store/chat.js b/pkg/interface/src/store/chat.js new file mode 100644 index 000000000..fc3881b99 --- /dev/null +++ b/pkg/interface/src/store/chat.js @@ -0,0 +1,51 @@ +import ContactReducer from '../reducers/contact-update'; +import ChatReducer from '../reducers/chat-update'; +import InviteReducer from '../reducers/invite-update'; +import PermissionReducer from '../reducers/permission-update'; +import MetadataReducer from '../reducers/metadata-update'; +import S3Reducer from '../reducers/s3-update'; +import LocalReducer from '../reducers/local'; + +import BaseStore from './base'; + +export default class ChatStore extends BaseStore { + constructor() { + super(); + this.permissionReducer = new PermissionReducer(); + this.contactReducer = new ContactReducer(); + this.chatReducer = new ChatReducer(); + this.inviteReducer = new InviteReducer(); + this.s3Reducer = new S3Reducer(); + this.metadataReducer = new MetadataReducer(); + this.localReducer = new LocalReducer(); + } + + initialState() { + return { + inbox: {}, + chatSynced: null, + contacts: {}, + permissions: {}, + invites: {}, + associations: { + chat: {}, + contacts: {} + }, + sidebarShown: true, + pendingMessages: new Map([]), + chatInitialized: false, + s3: {} + }; + } + + reduce(data, state) { + this.permissionReducer.reduce(data, this.state); + this.contactReducer.reduce(data, this.state); + this.chatReducer.reduce(data, this.state); + this.inviteReducer.reduce(data, this.state); + this.metadataReducer.reduce(data, this.state); + this.localReducer.reduce(data, this.state); + this.s3Reducer.reduce(data, this.state); + } +} + diff --git a/pkg/interface/src/store/groups.js b/pkg/interface/src/store/groups.js new file mode 100644 index 000000000..730a199a2 --- /dev/null +++ b/pkg/interface/src/store/groups.js @@ -0,0 +1,45 @@ +import ContactReducer from '../reducers/contact-update'; +import GroupReducer from '../reducers/group-update'; +import InviteReducer from '../reducers/invite-update'; +import PermissionReducer from '../reducers/permission-update'; +import MetadataReducer from '../reducers/metadata-update'; +import LocalReducer from '../reducers/local'; +import S3Reducer from '../reducers/s3-update'; + +import BaseStore from './base'; + + +export default class GroupsStore extends BaseStore { + constructor() { + super(); + this.groupReducer = new GroupReducer(); + this.permissionReducer = new PermissionReducer(); + this.contactReducer = new ContactReducer(); + this.inviteReducer = new InviteReducer(); + this.metadataReducer = new MetadataReducer(); + this.s3Reducer = new S3Reducer(); + this.localReducer = new LocalReducer(); + } + + initialState() { + return { + contacts: {}, + groups: {}, + associations: {}, + permissions: {}, + invites: {}, + s3: {} + }; + } + + reduce(data, state) { + this.groupReducer.reduce(json, this.state); + this.permissionReducer.reduce(json, this.state); + this.contactReducer.reduce(json, this.state); + this.inviteReducer.reduce(json, this.state); + this.metadataReducer.reduce(json, this.state); + this.s3Reducer.reduce(json, this.state); + this.localReducer.reduce(json, this.state); + } +} + diff --git a/pkg/interface/src/store/links.js b/pkg/interface/src/store/links.js new file mode 100644 index 000000000..ba28d58ed --- /dev/null +++ b/pkg/interface/src/store/links.js @@ -0,0 +1,55 @@ +import GroupReducer from '../reducers/group-update'; +import ContactReducer from '../reducers/contact-update'; +import PermissionReducer from '../reducers/permission-update'; +import MetadataReducer from '../reducers/metadata-update'; +import InviteReducer from '../reducers/invite-update'; +import LinkReducer from '../reducers/link-update'; +import ListenReducer from '../reducers/listen-update'; +import LocalReducer from '../reducers/local'; + +import BaseStore from './base'; + + +export default class LinksStore extends BaseStore { + constructor() { + super(); + this.groupReducer = new GroupReducer(); + this.contactReducer = new ContactReducer(); + this.permissionReducer = new PermissionReducer(); + this.metadataReducer = new MetadataReducer(); + this.inviteReducer = new InviteReducer(); + this.localReducer = new LocalReducer(); + this.linkReducer = new LinkReducer(); + this.listenReducer = new ListenReducer(); + } + + initialState() { + return { + contacts: {}, + groups: {}, + associations: { + link: {}, + contacts: {} + }, + invites: {}, + links: {}, + listening: new Set(), + comments: {}, + seen: {}, + permissions: {}, + sidebarShown: true + }; + } + + reduce(data, state) { + this.groupReducer.reduce(json, this.state); + this.contactReducer.reduce(json, this.state); + this.permissionReducer.reduce(json, this.state); + this.metadataReducer.reduce(json, this.state); + this.inviteReducer.reduce(json, this.state); + this.localReducer.reduce(json, this.state); + this.linkReducer.reduce(json, this.state); + this.listenReducer.reduce(json, this.state); + } +} + diff --git a/pkg/interface/src/store/publish.js b/pkg/interface/src/store/publish.js new file mode 100644 index 000000000..5d996badf --- /dev/null +++ b/pkg/interface/src/store/publish.js @@ -0,0 +1,45 @@ +import BaseStore from './base'; + +import GroupReducer from '../reducers/group-update'; +import PublishReducer from '../reducers/publish-update'; +import InviteReducer from '../reducers/invite-update'; +import PublishResponseReducer from '../reducers/publish-response'; +import PermissionReducer from '../reducers/permission-update'; +import MetadataReducer from '../reducers/metadata-update'; + +export default class PublishStore extends BaseStore { + constructor() { + super(); + + this.groupReducer = new GroupReducer(); + this.publishReducer = new PublishReducer(); + this.inviteReducer = new InviteReducer(); + this.responseReducer = new PublishResponseReducer(); + this.permissionReducer = new PermissionReducer(); + this.metadataReducer = new MetadataReducer(); + } + + initialState() { + return { + notebooks: {}, + groups: {}, + contacts: {}, + associations: { + contacts: {} + }, + permissions: {}, + invites: {}, + sidebarShown: true + }; + } + + reduce(data, state) { + this.groupReducer.reduce(data, this.state); + this.publishReducer.reduce(data, this.state); + this.permissionReducer.reduce(data, this.state); + this.metadataReducer.reduce(data, this.state); + this.inviteReducer.reduce(data, this.state); + this.responseReducer.reduce(data, this.state); + } +} +