Finished Frontend notifications, added file prio (needs test), started Settings Button work

This commit is contained in:
2018-01-23 23:21:25 -05:00
parent 5856052f82
commit 52e245d11f
15 changed files with 241 additions and 126 deletions

View File

@@ -18,6 +18,8 @@ let fileList = [];
let RSSList = [];
let RSSTorrentList = [];
let serverMessage = [];
let serverPushMessage = [];
let webSocketState = false;
var torrentListRequest = {
messageType: "torrentListRequest"
@@ -29,7 +31,7 @@ var torrentListRequest = {
//websocket is started in kickwebsocket.js and is picked up here so "ws" is already defined 22
ws.onmessage = function (evt) { //When we recieve a message from the websocket
var serverMessage = JSON.parse(evt.data)
//console.log("message", serverMessage.MessageType)
console.log("message", serverMessage.MessageType)
switch (serverMessage.MessageType) {
case "torrentList":
@@ -125,10 +127,11 @@ ws.onmessage = function (evt) { //When we recieve a message from the websocket
PublishDate: serverMessage.Torrents[i].PubDate,
})
}
break;
case "serverPushMessage":
console.log("Server push notification receieved", evt.data)
serverMessage = [serverMessage.Type, serverMessage.body];
this.props.newServerMessage(serverMessage)
console.log("SERVER PUSHED MESSAGE", serverMessage)
serverPushMessage = [serverMessage.MessageLevel, serverMessage.Payload];
break;
}
}
@@ -197,6 +200,10 @@ class BackendSocket extends React.Component {
() => this.tick(),
2000
);
if (ws.readyState === (ws.CONNECTING || ws.OPEN)){ //checking to make sure we have a websocket connection
webSocketState = true
this.props.webSocketStateUpdate(webSocketState)
}
}
@@ -211,9 +218,17 @@ class BackendSocket extends React.Component {
if (this.props.RSSTorrentList != RSSTorrentList & this.props.RSSModalOpen == true){
this.props.RSSTorrentList(RSSTorrentList) //pushing the new RSSTorrentList to Redux
}
if (this.props.serverPushMessage != serverPushMessage & serverPushMessage[0] != null){
console.log("PROPSSERVER", this.props.serverPushMessage, "SERVERPUSH", serverPushMessage)
this.props.newServerMessage(serverPushMessage)
}
ws.send(JSON.stringify(torrentListRequest))//talking to the server to get the torrent list
if (ws.readyState === ws.CLOSED){ //if our websocket gets closed inform the user
webSocketState = false
this.props.webSocketStateUpdate(webSocketState)
}
//console.log("Torrentlist", torrents)
this.props.setButtonState(this.props.selection) //forcing an update to the buttons
this.props.newTorrentList(torrents) //sending the list of torrents to torrentlist.js
@@ -243,7 +258,7 @@ class BackendSocket extends React.Component {
componentWillReceiveProps (nextProps) {
console.log("Lenght", nextProps.selectionHashes.length, "value", nextProps.selectionHashes)
console.log("Length", nextProps.selectionHashes.length, "value", nextProps.selectionHashes)
if (nextProps.selectionHashes.length === 1){ //if we have a selection pass it on for the tabs to verify
this.selectionHandler(nextProps.selectionHashes, nextProps.selectedTab)
}
@@ -271,6 +286,7 @@ const mapStateToProps = state => {
selection: state.selection,
RSSModalOpen: state.RSSModalOpen,
RSSTorrentList: state.RSSTorrentList,
serverPushMessage: state.serverPushMessage
};
}
@@ -285,7 +301,8 @@ const mapDispatchToProps = dispatch => {
setButtonState: (buttonState) => dispatch({type: actionTypes.SET_BUTTON_STATE, buttonState}),
newRSSFeedStore: (RSSList) => dispatch({type: actionTypes.NEW_RSS_FEED_STORE, RSSList}),
RSSTorrentList: (RSSTorrentList) => dispatch({type: actionTypes.RSS_TORRENT_LIST, RSSTorrentList}),
newServerMessage: (serverMessage) => dispatch({type: actionTypes.SERVER_MESSAGE, serverMessage}),
newServerMessage: (serverPushMessage) => dispatch({type: actionTypes.SERVER_MESSAGE, serverPushMessage}),
webSocketStateUpdate: (webSocketState) => dispatch({type: actionTypes.WEBSOCKET_STATE, webSocketState}),
//changeSelection: (selection) => dispatch({type: actionTypes.CHANGE_SELECTION, selection}),//forcing an update to the buttons
}

View File

@@ -38,10 +38,7 @@ class FileTab extends React.Component {
fileSelection: [],
selected: [],
};
this.changeColumnOrder = columnOrder => this.setState({columnOrder});
this.changeColumnWidths = columnWidths => this.setState({columnWidths});
this.changeSorting = sorting => this.setState({sorting});
@@ -58,41 +55,41 @@ class FileTab extends React.Component {
selectedRows.push(this.props.fileList[element]) //pushing the selected rows out of torrentlist
});
this.setState({fileSelection: selectedRows})
}
}
}
sendPriorityRequest = (priority, sendfileNames) => {
sendPriorityRequest = (priority, selectionHash) => {
let filePaths = []
this.state.fileSelection.forEach(element => {
console.log("element", element)
sendFileNames.push(element.FilePath)
filePaths.push(element.FilePath)
})
let setFilePriority = {
MessageType: "setFilePriority",
Payload: sendFileNames,
MessageDetail: priority,
MessageDetailTwo: selectionHash,
Payload: filePaths,
}
console.log(JSON.stringify(setFilePriority))
ws.send(JSON.stringify(setFilePriority))
}
setHighPriority = () => {
let priorty = "High"
let priority = "High"
let selectionHash = this.props.selectionHashes[0] //getting the first element (should be the only one)
let sendFileNames = [selectionHash, "High"]// adding the selection hash as the first element will be stripped out by the server, second element is the prioty request
this.sendPriorityRequest(priority, selectionHash)
}
setNormalPriority = () => {
let priorty = "Normal"
let priority = "Normal"
let selectionHash = this.props.selectionHashes[0] //getting the first element (should be the only one)
let sendFileNames = [selectionHash, "Normal"]// adding the selection hash as the first element will be stripped out by the server, second element is the prioty request
this.sendPriorityRequest(priority, selectionHash)
}
setCancelPriority = () => {
let priorty = "Cancel"
let priority = "Cancel"
let selectionHash = this.props.selectionHashes[0] //getting the first element (should be the only one)
let sendFileNames = [selectionHash, "Cancel"]// adding the selection hash as the first element will be stripped out by the server, second element is the prioty request
this.sendPriorityRequest(priority, selectionHash)
}
render() {
return (
//Buttons here
@@ -140,15 +137,11 @@ const mapStateToProps = state => {
return {
selectionHashes: state.selectionHashes,
fileList: state.fileList,
//fileSelectionNames: state.fileSelectionNames,
};
}
const mapDispatchToProps = dispatch => {
return {
//changeFileSelection: (fileSelection) => dispatch({type: actionTypes.CHANGE_FILE_SELECTION, fileSelection}),
sendSelectionHashes: (selectionHashes) => dispatch({type: actionTypes.SELECTION_HASHES, selectionHashes}),
}
}

View File

@@ -81,7 +81,7 @@ const inlineStyle = {
const mapStateToProps = state => {
return {
RSSModalOpen: state.RSSModalOpen,
};
}
}
const mapDispatchToProps = dispatch => {

View File

@@ -58,6 +58,9 @@ export default class addTorrentPopup extends React.Component {
}
console.log("Sending magnet link: ", magnetLinkMessage);
ws.send(JSON.stringify(magnetLinkMessage));
this.setState({magnetLinkValue: ""})
this.setState({storageValue: ``})
console.log("Magnet Link", this.state.magnetLinkValue)
}
setMagnetLinkValue = (event) => {

View File

@@ -11,25 +11,31 @@ import { ToastContainer, toast } from 'react-toastify';
class Notifications extends React.Component {
constructor(props){
super(props);
this.state = { serverMessage: ["info", "A props message"]}
}
componentWillReceiveProps(nextprops) {
if (nextprops.serverMessage != this.state.serverMessage) {
toast(this.state.serverMessage[1])
if (nextprops.serverPushMessage != this.props.serverPushMessage) {
toast(nextprops.serverPushMessage[1], {
type: nextprops.serverPushMessage[0]
})
console.log("Server Push Message", nextprops.serverPushMessage)
}
if (nextprops.webSocketState != this.props.webSocketState){
if (nextprops.webSocketState == true){
toast.success("Websocket Connection Open!")
} else {
toast("Websocket Connection Closed!", {
type: "error",
autoClose: false,
})
}
}
}
componentDidMount(){
toast("Testing toast custom settings")
}
render() {
return (
<div>
<ToastContainer type={this.state.serverMessage[0]} position={toast.POSITION.TOP_RIGHT} autoClose={8000} />
<ToastContainer position={toast.POSITION.TOP_RIGHT} autoClose={8000} />
</div>
);
}
@@ -39,7 +45,8 @@ class Notifications extends React.Component {
const mapStateToProps = state => {
return {
//serverMessage: state.serverMessage,
serverPushMessage: state.serverPushMessage,
webSocketState: state.webSocketState,
};
}

View File

@@ -11,4 +11,5 @@ export const CHANGE_FILE_SELECTION = 'CHANGE_FILE_SELECTION';
export const NEW_RSS_FEED_STORE = 'NEW_RSS_FEED_STORE';
export const RSS_MODAL_OPEN_STATE = 'RSS_MODAL_OPEN_STATE';
export const RSS_TORRENT_LIST = 'RSS_TORRENT_LIST';
export const SERVER_MESSAGE = 'SERVER_MESSAGE';
export const SERVER_MESSAGE = 'SERVER_MESSAGE';
export const WEBSOCKET_STATE = 'WEBSOCKET_STATE';

View File

@@ -18,7 +18,8 @@ const initialState = {
RSSList: [],
RSSTorrentList: [],
RSSModalOpen: false,
serverMessage: [],
serverPushMessage: [],
webSocketState: false
}
@@ -26,6 +27,12 @@ const initialState = {
const reducer = (state = initialState, action) => {
switch(action.type){
case actionTypes.WEBSOCKET_STATE:
console.log("Websocket closed...")
return {
...state,
webSocketState: action.webSocketState,
}
case actionTypes.CHANGE_SELECTION:
console.log("Change Selection", action.selection)
@@ -100,10 +107,10 @@ const reducer = (state = initialState, action) => {
}
case actionTypes.SERVER_MESSAGE:
console.log("New server push message", action.serverMessage)
console.log("New server push message", action.serverPushMessage)
return {
...state,
serverMessage: action.serverMessage
serverPushMessage: action.serverPushMessage
}
case actionTypes.SET_BUTTON_STATE: