diff --git a/package.json b/package.json index a0caca45..8ed72162 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "scripts": { "dev": "node . --unhandled-rejections=strict", "dev:node": "NODE_ENV=development webpack --config webpack.node.config.js --mode development", + "prod": "NODE_ENV=production node . --unhandled-rejections=strict", "build": "next build", "start": "electron .", "electron": "electron ./electron/main.js ", diff --git a/pages/index.js b/pages/index.js index 9b5b0f06..01dc7b45 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,39 +1,39 @@ -import * as React from "react"; -import * as NavigationData from "~/common/navigation-data"; -import * as Actions from "~/common/actions"; -import * as State from "~/common/state"; +import * as React from 'react'; +import * as NavigationData from '~/common/navigation-data'; +import * as Actions from '~/common/actions'; +import * as State from '~/common/state'; -import SceneDataTransfer from "~/scenes/SceneDataTransfer"; -import SceneDeals from "~/scenes/SceneDeals"; -import SceneEditAccount from "~/scenes/SceneEditAccount"; -import SceneFile from "~/scenes/SceneFile"; -import SceneFilesFolder from "~/scenes/SceneFilesFolder"; -import SceneHome from "~/scenes/SceneHome"; -import SceneLogs from "~/scenes/SceneLogs"; -import SceneMiners from "~/scenes/SceneMiners"; -import ScenePaymentChannels from "~/scenes/ScenePaymentChannels"; -import ScenePeers from "~/scenes/ScenePeers"; -import SceneSettings from "~/scenes/SceneSettings"; -import SceneStats from "~/scenes/SceneStats"; -import SceneStatus from "~/scenes/SceneStatus"; -import SceneStorageMarket from "~/scenes/SceneStorageMarket"; -import SceneWallet from "~/scenes/SceneWallet"; +import SceneDataTransfer from '~/scenes/SceneDataTransfer'; +import SceneDeals from '~/scenes/SceneDeals'; +import SceneEditAccount from '~/scenes/SceneEditAccount'; +import SceneFile from '~/scenes/SceneFile'; +import SceneFilesFolder from '~/scenes/SceneFilesFolder'; +import SceneHome from '~/scenes/SceneHome'; +import SceneLogs from '~/scenes/SceneLogs'; +import SceneMiners from '~/scenes/SceneMiners'; +import ScenePaymentChannels from '~/scenes/ScenePaymentChannels'; +import ScenePeers from '~/scenes/ScenePeers'; +import SceneSettings from '~/scenes/SceneSettings'; +import SceneStats from '~/scenes/SceneStats'; +import SceneStatus from '~/scenes/SceneStatus'; +import SceneStorageMarket from '~/scenes/SceneStorageMarket'; +import SceneWallet from '~/scenes/SceneWallet'; -import SidebarCreateWalletAddress from "~/components/sidebars/SidebarCreateWalletAddress"; -import SidebarDeleteWalletAddress from "~/components/sidebars/SidebarDeleteWalletAddress"; -import SidebarWalletSendFunds from "~/components/sidebars/SidebarWalletSendFunds"; -import SidebarFileStorageDeal from "~/components/sidebars/SidebarFileStorageDeal"; -import SidebarFileRetrievalDeal from "~/components/sidebars/SidebarFileRetrievalDeal"; -import SidebarCreatePaymentChannel from "~/components/sidebars/SidebarCreatePaymentChannel"; -import SidebarAddMiner from "~/components/sidebars/SidebarAddMiner"; -import SidebarAddPeer from "~/components/sidebars/SidebarAddPeer"; -import SidebarNotifications from "~/components/sidebars/SidebarNotifications"; -import SidebarRedeemPaymentChannel from "~/components/sidebars/SidebarRedeemPaymentChannel"; +import SidebarCreateWalletAddress from '~/components/sidebars/SidebarCreateWalletAddress'; +import SidebarDeleteWalletAddress from '~/components/sidebars/SidebarDeleteWalletAddress'; +import SidebarWalletSendFunds from '~/components/sidebars/SidebarWalletSendFunds'; +import SidebarFileStorageDeal from '~/components/sidebars/SidebarFileStorageDeal'; +import SidebarFileRetrievalDeal from '~/components/sidebars/SidebarFileRetrievalDeal'; +import SidebarCreatePaymentChannel from '~/components/sidebars/SidebarCreatePaymentChannel'; +import SidebarAddMiner from '~/components/sidebars/SidebarAddMiner'; +import SidebarAddPeer from '~/components/sidebars/SidebarAddPeer'; +import SidebarNotifications from '~/components/sidebars/SidebarNotifications'; +import SidebarRedeemPaymentChannel from '~/components/sidebars/SidebarRedeemPaymentChannel'; -import ApplicationNavigation from "~/components/core/ApplicationNavigation"; -import ApplicationHeader from "~/components/core/ApplicationHeader"; -import ApplicationLayout from "~/components/core/ApplicationLayout"; -import WebsitePrototypeWrapper from "~/components/core/WebsitePrototypeWrapper"; +import ApplicationNavigation from '~/components/core/ApplicationNavigation'; +import ApplicationHeader from '~/components/core/ApplicationHeader'; +import ApplicationLayout from '~/components/core/ApplicationLayout'; +import WebsitePrototypeWrapper from '~/components/core/WebsitePrototypeWrapper'; const getCurrentNavigationStateById = (navigation, targetId) => { let target = null; @@ -82,7 +82,7 @@ export default class IndexPage extends React.Component { currentIndex: 0, data: null, selected: { - address: "", + address: '', }, viewer: State.getInitialState(this.props), sidebar: null, @@ -93,36 +93,36 @@ export default class IndexPage extends React.Component { this._socket = new WebSocket(`ws://localhost:${this.props.wsPort}`); this._socket.onmessage = (m) => { console.log(m); - if (m.type === "message") { + if (m.type === 'message') { const parsed = JSON.parse(m.data); - if (parsed.action === "UPDATE_VIEWER") { + if (parsed.action === 'UPDATE_VIEWER') { this.rehydrate({ data: parsed.data }); } } }; - window.addEventListener("dragenter", this._handleDragEnter); - window.addEventListener("dragleave", this._handleDragLeave); - window.addEventListener("dragover", this._handleDragOver); - window.addEventListener("drop", this._handleDrop); + window.addEventListener('dragenter', this._handleDragEnter); + window.addEventListener('dragleave', this._handleDragLeave); + window.addEventListener('dragover', this._handleDragOver); + window.addEventListener('drop', this._handleDrop); } componentWillUnmount() { - window.removeEventListener("dragenter", this._handleDragEnter); - window.removeEventListener("dragleave", this._handleDragLeave); - window.removeEventListener("dragover", this._handleDragOver); - window.removeEventListener("drop", this._handleDrop); + window.removeEventListener('dragenter', this._handleDragEnter); + window.removeEventListener('dragleave', this._handleDragLeave); + window.removeEventListener('dragover', this._handleDragOver); + window.removeEventListener('drop', this._handleDrop); } _handleSetFile = async ({ file }) => { let data = new FormData(); - data.append("image", file); + data.append('image', file); const options = { - method: "POST", + method: 'POST', headers: { - Accept: "application/json", + Accept: 'application/json', }, body: data, }; @@ -137,17 +137,17 @@ export default class IndexPage extends React.Component { _handleDragEnter = (e) => { // TODO(jim): Styles. - console.log("dragenter", e); + console.log('dragenter', e); }; _handleDragLeave = (e) => { // TODO(jim): Styles. - console.log("dragleave", e); + console.log('dragleave', e); }; _handleDragOver = (e) => { e.preventDefault(); - console.log("dragover", e); + console.log('dragover', e); }; _handleDrop = async (e) => { @@ -155,7 +155,7 @@ export default class IndexPage extends React.Component { if (e.dataTransfer.items) { for (var i = 0; i < e.dataTransfer.items.length; i++) { - if (e.dataTransfer.items[i].kind === "file") { + if (e.dataTransfer.items[i].kind === 'file') { var file = e.dataTransfer.items[i].getAsFile(); console.log(file.name); await this._handleSetFile({ file }); @@ -164,7 +164,7 @@ export default class IndexPage extends React.Component { } } - this._handleAction({ type: "SIDEBAR", value: "SIDEBAR_FILE_STORAGE_DEAL" }); + this._handleAction({ type: 'SIDEBAR', value: 'SIDEBAR_FILE_STORAGE_DEAL' }); }; rehydrate = async ({ data }) => { @@ -173,11 +173,11 @@ export default class IndexPage extends React.Component { _handleSubmit = async (data) => { if (this.props.production) { - alert("TODO"); + alert('TODO'); return this._handleDismissSidebar(); } - if (data.type === "CREATE_WALLET_ADDRESS") { + if (data.type === 'CREATE_WALLET_ADDRESS') { const address = await Actions.createWalletAddress({ name: data.name, type: data.wallet_type, @@ -185,7 +185,7 @@ export default class IndexPage extends React.Component { }); } - if (data.type === "SEND_WALLET_ADDRESS_FILECOIN") { + if (data.type === 'SEND_WALLET_ADDRESS_FILECOIN') { const response = await Actions.sendWalletAddressFilecoin({ source: data.source, target: data.target, @@ -217,19 +217,19 @@ export default class IndexPage extends React.Component { }; _handleAction = (options) => { - if (options.type === "NAVIGATE") { + if (options.type === 'NAVIGATE') { return this._handleNavigateTo({ id: options.value }, options.data); } - if (options.type === "ACTION") { + if (options.type === 'ACTION') { return alert(JSON.stringify(options)); } - if (options.type === "DOWNLOAD") { + if (options.type === 'DOWNLOAD') { return alert(JSON.stringify(options)); } - if (options.type === "SIDEBAR") { + if (options.type === 'SIDEBAR') { return this.setState({ sidebar: this.sidebars[options.value] }); } @@ -329,11 +329,14 @@ export default class IndexPage extends React.Component { }; render() { - if (this.props.production) { - return null; - } + // Note(colin): Removed so build will work in electron + // if (this.props.production) { + // return null; + // } - const navigation = NavigationData.generate(this.state.viewer.library); + const navigation = Fixtures.generateNavigationState( + this.state.viewer.library + ); const next = this.state.history[this.state.currentIndex]; const current = getCurrentNavigationStateById(navigation, next.id); @@ -388,17 +391,22 @@ export default class IndexPage extends React.Component { } const title = `Prototype 0.0.1 : ${current.target.pageTitle}`; - const description = "This is an early preview."; - const url = "https://fps.onrender.com/v1"; + const description = 'This is an early preview.'; + const url = 'https://fps.onrender.com/v1'; return ( - + + onDismissSidebar={this._handleDismissSidebar} + > {scene} diff --git a/server.js b/server.js index 9dcebd62..9a56fa8e 100644 --- a/server.js +++ b/server.js @@ -29,9 +29,6 @@ const path = require('path'); const app = next({ dev: false, dir: __dirname, - conf: { - distDir: path.resolve('./.next'), - }, quiet: false, }); const nextRequestHandler = app.getRequestHandler(); @@ -77,107 +74,104 @@ app.prepare().then(async () => { local: null, }; - if (!production) { - try { - // NOTE(daniel): Wipe all of the local data when --reset-data flag is added to npm run dev. - if (resetData) { - await Utilities.resetFileSystem(); - } + try { + // TODO(jim): Remove later. + // We wipe all of the local data each time you run the application. + await Utilities.resetFileSystem(); - const updates = await Utilities.refresh({ PG: PowerGate }); - state = await Utilities.updateStateData(state, updates); - console.log('[ prototype ] updated without token'); + const updates = await Utilities.refresh({ PG: PowerGate }); + state = await Utilities.updateStateData(state, updates); + console.log('[ prototype ] updated without token'); - // NOTE(jim): This is a configuration folder with all of the client tokens. - // TODO(jim): Unnecessary if we use a local and remote postgres. - const dirnameData = path.join(__dirname, '/.data'); - if (!FS.existsSync(dirnameData)) { - FS.mkdirSync(dirnameData, { recursive: true }); - } - - // NOTE(jim): This will create a token for authentication with powergate. - // TODO(jim): Roll this up into Postgres instead. - const dirnamePowergate = path.join(__dirname, '/.data/powergate-token'); - if (!FS.existsSync(dirnamePowergate)) { - const FFS = await PowerGate.ffs.create(); - state.token = FFS.token ? FFS.token : null; - - // NOTE(jim): Write a new token file. - if (state.token) { - FS.writeFileSync(dirnamePowergate, state.token); - } - } else { - state.token = FS.readFileSync(dirnamePowergate, 'utf8'); - } - - if (state.token) { - console.log('[ prototype ] powergate token:', state.token); - PowerGate.setToken(state.token); - } - - const tokenUpdates = await Utilities.refreshWithToken({ - PG: PowerGate, - }); - state = await Utilities.updateStateData(state, tokenUpdates); - console.log('[ prototype ] updated with token'); - - // NOTE(jim): Local library retrieval or creation - // TODO(jim): Needs to support nested folders in the future. - // TODO(jim): May consider a move to buckets. - const dirnameLibrary = path.join(__dirname, '/.data/library.json'); - if (!FS.existsSync(dirnameLibrary)) { - const librarySchema = { - library: [ - { - ...Utilities.createFolder({ id: Constants.FILE_STORAGE_URL }), - file: 'Files', - name: 'Files', - }, - ], - }; - - FS.writeFileSync(dirnameLibrary, JSON.stringify(librarySchema)); - state.library = librarySchema.library; - } else { - const parsedLibrary = FS.readFileSync(dirnameLibrary, 'utf8'); - state.library = JSON.parse(parsedLibrary).library; - } - - // NOTE(jim): Local settings retrieval or creation - // TODO(jim): Move this to postgres later. - const dirnameLocalsettings = path.join( - __dirname, - '/.data/local-settings.json' - ); - if (!FS.existsSync(dirnameLocalsettings)) { - const localSettingsSchema = { - local: { - photo: null, - name: `node-${uuid()}`, - settings_deals_auto_approve: false, - }, - }; - - FS.writeFileSync( - dirnameLocalsettings, - JSON.stringify(localSettingsSchema) - ); - state.local = localSettingsSchema.local; - } else { - const parsedLocal = FS.readFileSync(dirnameLocalsettings, 'utf8'); - state.local = JSON.parse(parsedLocal).local; - } - } catch (e) { - console.log(e); - console.log('[ prototype ] "/" -- WILL REDIRECT TO /SYSTEM '); - console.log( - '[ prototype ] SLATE WILL NOT RUN LOCALLY UNTIL YOU HAVE ' - ); - console.log('[ prototype ] PROPERLY CONFIGURED POWERGATE AND '); - console.log( - '[ prototype ] CONNECTED TO THE FILECOIN NETWORK (DEVNET/TESTNET) ' - ); + // NOTE(jim): This is a configuration folder with all of the client tokens. + // TODO(jim): Unnecessary if we use a local and remote postgres. + const dirnameData = path.join(__dirname, '/.data'); + if (!FS.existsSync(dirnameData)) { + FS.mkdirSync(dirnameData, { recursive: true }); } + + // NOTE(jim): This will create a token for authentication with powergate. + // TODO(jim): Roll this up into Postgres instead. + const dirnamePowergate = path.join(__dirname, '/.data/powergate-token'); + if (!FS.existsSync(dirnamePowergate)) { + const FFS = await PowerGate.ffs.create(); + state.token = FFS.token ? FFS.token : null; + + // NOTE(jim): Write a new token file. + if (state.token) { + FS.writeFileSync(dirnamePowergate, state.token); + } + } else { + state.token = FS.readFileSync(dirnamePowergate, 'utf8'); + } + + if (state.token) { + console.log('[ prototype ] powergate token:', state.token); + PowerGate.setToken(state.token); + } + + const tokenUpdates = await Utilities.refreshWithToken({ + PG: PowerGate, + }); + state = await Utilities.updateStateData(state, tokenUpdates); + console.log('[ prototype ] updated with token'); + + // NOTE(jim): Local library retrieval or creation + // TODO(jim): Needs to support nested folders in the future. + // TODO(jim): May consider a move to buckets. + const dirnameLibrary = path.join(__dirname, '/.data/library.json'); + if (!FS.existsSync(dirnameLibrary)) { + const librarySchema = { + library: [ + { + ...Utilities.createFolder({ id: Constants.FILE_STORAGE_URL }), + file: 'Files', + name: 'Files', + }, + ], + }; + + FS.writeFileSync(dirnameLibrary, JSON.stringify(librarySchema)); + state.library = librarySchema.library; + } else { + const parsedLibrary = FS.readFileSync(dirnameLibrary, 'utf8'); + state.library = JSON.parse(parsedLibrary).library; + } + + // NOTE(jim): Local settings retrieval or creation + // TODO(jim): Move this to postgres later. + const dirnameLocalsettings = path.join( + __dirname, + '/.data/local-settings.json' + ); + if (!FS.existsSync(dirnameLocalsettings)) { + const localSettingsSchema = { + local: { + photo: null, + name: `node-${uuid()}`, + settings_deals_auto_approve: false, + }, + }; + + FS.writeFileSync( + dirnameLocalsettings, + JSON.stringify(localSettingsSchema) + ); + state.local = localSettingsSchema.local; + } else { + const parsedLocal = FS.readFileSync(dirnameLocalsettings, 'utf8'); + state.local = JSON.parse(parsedLocal).local; + } + } catch (e) { + console.log(e); + console.log('[ prototype ] "/" -- WILL REDIRECT TO /SYSTEM '); + console.log( + '[ prototype ] SLATE WILL NOT RUN LOCALLY UNTIL YOU HAVE ' + ); + console.log('[ prototype ] PROPERLY CONFIGURED POWERGATE AND '); + console.log( + '[ prototype ] CONNECTED TO THE FILECOIN NETWORK (DEVNET/TESTNET) ' + ); } const server = express();