diff --git a/package.json b/package.json index 422c8e7..6df792c 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "node-sass": "^4.7.2", "preact": "^8.2.7", "preact-compat": "^3.17.0", + "query-string": "^5.0.1", "react": "^15.6.2", "react-dom": "^15.6.2", "react-fontawesome": "^1.6.1", diff --git a/src/actions/filter_subscribe.js b/src/actions/filter_subscribe.js index 76fe752..92e617f 100644 --- a/src/actions/filter_subscribe.js +++ b/src/actions/filter_subscribe.js @@ -3,9 +3,9 @@ import ws_send from '../socket'; export const FILTER_SUBSCRIBE = 'FILTER_SUBSCRIBE'; export const FILTER_UNSUBSCRIBE = 'FILTER_UNSUBSCRIBE'; -export function filter_subscribe(kind='torrent', criteria=[]) { +export function filter_subscribe(kind='torrent', criteria=[], serial=null) { return dispatch => { - const serial = ws_send(FILTER_SUBSCRIBE, { kind, criteria }); + const serial = ws_send(FILTER_SUBSCRIBE, { kind, criteria }, null, serial); dispatch({ type: FILTER_SUBSCRIBE, serial, kind, criteria }); }; } diff --git a/src/index.js b/src/index.js index 14f9663..eb7da3a 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,6 @@ import { ws_init } from './socket'; import { filter_subscribe } from './actions/filter_subscribe'; import { socket_uri, socket_update, SOCKET_STATE } from './actions/socket'; -import Nav from './ui/navigation'; import Main from './ui/main'; import Connection from './ui/connection'; @@ -33,12 +32,7 @@ const render = main => ReactDOM.render( -
-
+ {main}
, document.getElementById('root')); diff --git a/src/socket.js b/src/socket.js index 0813c0c..5bf3813 100644 --- a/src/socket.js +++ b/src/socket.js @@ -10,8 +10,8 @@ let queue = []; const getURI = ({ uri, password }) => `${uri}${password ? `?password=${encodeURIComponent(password)}` : ''}`; -export default function ws_send(type, body, callback = null) { - const _serial = serial++; +export default function ws_send(type, body, callback = null, __serial = null) { + const _serial = __serial !== null ? __serial : serial++; if (callback) { transactions[_serial] = callback; } diff --git a/src/ui/main.js b/src/ui/main.js index 322ba46..0bb5da2 100644 --- a/src/ui/main.js +++ b/src/ui/main.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import { Route, DefaultRoute } from 'react-router'; import { connect } from 'react-redux'; +import Nav from './navigation'; import TorrentTable from './torrent_table'; import AddTorrent from './add_torrent'; import TorrentDetails from './torrent_details'; @@ -10,17 +11,22 @@ import ConnectionOverlay from './connection'; export default class Main extends Component { render() { return ( -
-
- +
+
); } diff --git a/src/ui/navigation.js b/src/ui/navigation.js index f440f43..1a19378 100644 --- a/src/ui/navigation.js +++ b/src/ui/navigation.js @@ -1,7 +1,31 @@ import React from 'react'; +import { connect } from 'react-redux'; import { Link, NavLink } from 'react-router-dom'; +import { filter_subscribe } from '../actions/filter_subscribe'; +import { push } from 'react-router-redux'; +import query from 'query-string'; -export default function render(props) { +function search_qs(text) { + const qs = query.stringify({ + ...query.parse(location.search), + s: text || undefined + }); + return `${ + location.pathname === "/" ? location.pathname : "" + }${qs && "?" + qs}`; +} + +function update_filter(text, fs, location, dispatch) { + dispatch(push(search_qs(text))); +} + +function render(props) { + const { dispatch, router } = props; + const qs = query.parse(router.location.search); + const navto = where => e => { + e.preventDefault(); + dispatch(push(where)); + }; return ; } + +export default connect(state => ({ + filter_subscribe: state.filter_subscribe, + router: state.router, +}))(render);