Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
/ Orion Public archive

Add share option to properties and storagelist #180

Merged
merged 3 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/util/shareMenuTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { remote } from 'electron'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this to app/lib/sharing (example) ?

import {
getURLFromHash,
shareViaFacebook,
shareViaTwitter,
shareViaEmail
} from '../windows/Storage/fileIntegration'

const shareMenuTemplate = (hash) => ([{
label: 'Copy URL',
click: () => {
remote.clipboard.writeText(getURLFromHash(hash))
}
}, {
label: 'via Email',
click: () => {
shareViaEmail(hash)
}
}, {
label: 'via Facebook',
click: () => {
shareViaFacebook(hash)
}
}, {
label: 'via Twitter',
click: () => {
shareViaTwitter(hash)
}
}])

export default shareMenuTemplate
13 changes: 13 additions & 0 deletions app/windows/Details/renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import cx from 'classnames'
import { Window, Toolbar, Actionbar, ButtonGroup } from 'react-photonkit'
import Button from '../../components/Button'
import { trackEvent } from '../../stats'
import shareMenuTemplate from '../../util/shareMenuTemplate'

// Load Components
import InformationTab from './Components/InformationTab'
Expand All @@ -37,6 +38,8 @@ class DetailsWindow extends React.Component {
componentDidMount () {
trackEvent('DetailsWindowOpen', {})
promiseIPFSReady().then(this.fetchData)

this.shareMenu = remote.Menu.buildFromTemplate(shareMenuTemplate(hash))
}

fetchData = () => {
Expand Down Expand Up @@ -78,6 +81,10 @@ class DetailsWindow extends React.Component {
openInBrowser([hash])
}

handleShare = () => {
this.shareMenu.popup({})
}

handlePin = () => {
this.setState({ isUpdatingPin: true })
pinObject(hash)
Expand Down Expand Up @@ -137,6 +144,12 @@ class DetailsWindow extends React.Component {
onClick={this.handleOpenInBrowser}
pullRight
/>
<Button
text="Share"
glyph='share'
onClick={this.handleShare}
pullRight
/>
</Actionbar>
</Toolbar>

Expand Down
14 changes: 10 additions & 4 deletions app/windows/Storage/Components/StorageElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { Icon } from 'react-photonkit'
import { saveFileToPath, publishToIPNS } from '../../../api'

import {
proptAndRemoveObjects, openInBrowser
proptAndRemoveObjects,
openInBrowser
} from '../fileIntegration'
import shareMenuTemplate from '../../../util/shareMenuTemplate'

import DetailsWindow from '../../Details/window'
import formatElement from '../../../util/format-element'
Expand All @@ -25,6 +27,10 @@ class StorageElement extends React.Component {
openInBrowser([this.props.element.hash])
}
},
{
label: 'Share',
submenu: shareMenuTemplate(this.props.element.hash)
},
{
type: 'separator'
},
Expand Down Expand Up @@ -145,20 +151,20 @@ class StorageElement extends React.Component {

return (
<tr
className={ selected ? 'active' : ''}
className={selected ? 'active' : ''}
onClick={(event) => { this._handleRowSelection(event, el) }}
key={el.hash}
onContextMenu={this._handleContextMenu.bind(this)}
>

{ this.props.storageStore
{this.props.storageStore
? <td>
<input
checked={selected}
type='checkbox'
/>
</td>
: <td></td> }
: <td></td>}

<td>
{
Expand Down
27 changes: 25 additions & 2 deletions app/windows/Storage/fileIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,34 @@ export function proptAndRemoveObjects (elements) {

/**
* Open hashes in a browser
* @param {string[]} hashes
*/
export function openInBrowser (hashes) {
const gatewayURL = Settings.get('gatewayURL') || 'https://siderus.io'
hashes.forEach(hash => {
shell.openExternal(`${gatewayURL}/ipfs/${hash}`)
shell.openExternal(getURLFromHash(hash))
})
return Promise.resolve(hashes)
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move these functions into app/lib/sharing/?

* Constructs a shareable url with the gateway from settings or the default one
*
* @param {string} hash
* @returns {string}
*/
export function getURLFromHash (hash) {
const gatewayURL = Settings.get('gatewayURL') || 'https://siderus.io'
return `${gatewayURL}/ipfs/${hash}`
}

export function shareViaFacebook (hash) {
return shell.openExternal(`https://www.facebook.com/sharer.php?u=${getURLFromHash(hash)}`)
}

export function shareViaTwitter (hash) {
return shell.openExternal(`https://twitter.com/intent/tweet?text=${getURLFromHash(hash)}`)
}

export function shareViaEmail (hash) {
return shell.openExternal(`mailto:?body=${getURLFromHash(hash)}`)
}