Add notification while creating torrent file
parent
f912d82002
commit
a90c287989
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { Component, Fragment } from 'react';
|
import React, { Component, Fragment } from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { notifyAction } from '../../redux/stateActions';
|
import * as requestActions from '../../redux/requestActions';
|
||||||
import { saveAs } from 'file-saver/FileSaver';
|
import { saveAs } from 'file-saver/FileSaver';
|
||||||
import { client } from './FileSharing';
|
import { client } from './FileSharing';
|
||||||
|
|
||||||
|
|
@ -130,7 +130,7 @@ class FileChatEntry extends Component
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
notify : notifyAction
|
notify : requestActions.notify
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import React, { Component } from 'react';
|
||||||
import WebTorrent from 'webtorrent';
|
import WebTorrent from 'webtorrent';
|
||||||
import createTorrent from 'create-torrent';
|
import createTorrent from 'create-torrent';
|
||||||
import dragDrop from 'drag-drop';
|
import dragDrop from 'drag-drop';
|
||||||
|
import randomString from 'random-string';
|
||||||
import * as stateActions from '../../redux/stateActions';
|
import * as stateActions from '../../redux/stateActions';
|
||||||
import * as requestActions from '../../redux/requestActions';
|
import * as requestActions from '../../redux/requestActions';
|
||||||
import { store } from '../../store';
|
import { store } from '../../store';
|
||||||
|
|
@ -25,12 +26,22 @@ const notifyPeers = (file) =>
|
||||||
|
|
||||||
const shareFiles = async (files) =>
|
const shareFiles = async (files) =>
|
||||||
{
|
{
|
||||||
|
const notification =
|
||||||
|
{
|
||||||
|
id: randomString({ length: 6 }).toLowerCase(),
|
||||||
|
text: 'Creating torrent',
|
||||||
|
type: 'info'
|
||||||
|
};
|
||||||
|
|
||||||
|
store.dispatch(stateActions.addNotification(notification));
|
||||||
|
|
||||||
createTorrent(files, (err, torrent) =>
|
createTorrent(files, (err, torrent) =>
|
||||||
{
|
{
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
console.error('Error creating torrent', err);
|
return store.dispatch(requestActions.notify({
|
||||||
return;
|
text: 'An error occured while uploading a file'
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingTorrent = client.get(torrent);
|
const existingTorrent = client.get(torrent);
|
||||||
|
|
@ -41,9 +52,15 @@ const shareFiles = async (files) =>
|
||||||
magnet: existingTorrent.magnetURI
|
magnet: existingTorrent.magnetURI
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
client.seed(files, (newTorrent) =>
|
client.seed(files, (newTorrent) =>
|
||||||
{
|
{
|
||||||
|
store.dispatch(stateActions.removeNotification(notification.id));
|
||||||
|
|
||||||
|
store.dispatch(requestActions.notify({
|
||||||
|
text: 'Torrent successfully created'
|
||||||
|
}))
|
||||||
|
|
||||||
notifyPeers({
|
notifyPeers({
|
||||||
magnet : newTorrent.magnetURI
|
magnet : newTorrent.magnetURI
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue