From e1d23667bcb3d7d569f08f3dc6c07e482daa7b42 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Sun, 30 Apr 2017 10:19:59 +0700 Subject: [PATCH] Fix NSFW blurring on search and make search show/hide smarter --- ui/js/actions/search.js | 12 ++++++++++++ ui/js/component/fileTileStream/index.js | 2 +- ui/js/component/fileTileStream/view.jsx | 8 +++++++- ui/js/component/header/index.js | 4 ++++ ui/js/constants/action_types.js | 4 ++-- ui/js/page/discover/index.js | 2 ++ ui/js/page/discover/view.jsx | 18 ++++++++++++++++++ ui/js/reducers/search.js | 12 ++++++++++++ ui/js/selectors/search.js | 5 +++++ 9 files changed, 63 insertions(+), 4 deletions(-) diff --git a/ui/js/actions/search.js b/ui/js/actions/search.js index a4b1e83c4..b56c752cc 100644 --- a/ui/js/actions/search.js +++ b/ui/js/actions/search.js @@ -45,3 +45,15 @@ export function doSearchContent(query) { }) } } + +export function doActivateSearch() { + return { + type: types.ACTIVATE_SEARCH, + } +} + +export function doDeactivateSearch() { + return { + type: types.DEACTIVATE_SEARCH, + } +} diff --git a/ui/js/component/fileTileStream/index.js b/ui/js/component/fileTileStream/index.js index c297eec25..d212dfdae 100644 --- a/ui/js/component/fileTileStream/index.js +++ b/ui/js/component/fileTileStream/index.js @@ -35,7 +35,7 @@ const makeSelect = () => { fileInfo: selectFileInfoForUri(state, props), fetchingAvailability: selectFetchingAvailabilityForUri(state, props), selectAvailabilityForUri: selectAvailabilityForUri(state, props), - obscureNswf: selectObscureNsfw(state), + obscureNsfw: selectObscureNsfw(state), metadata: selectMetadataForUri(state, props), source: selectSourceForUri(state, props), }) diff --git a/ui/js/component/fileTileStream/view.jsx b/ui/js/component/fileTileStream/view.jsx index fd3a2b32c..50e221b9f 100644 --- a/ui/js/component/fileTileStream/view.jsx +++ b/ui/js/component/fileTileStream/view.jsx @@ -75,7 +75,13 @@ class FileTileStream extends React.Component {
- navigate(`show=${uri}`)}> + navigate(`show=${uri}`)}> + {metadata && metadata.thumbnail ? + + : + + } +
diff --git a/ui/js/component/header/index.js b/ui/js/component/header/index.js index 90b9293f6..02ca2f2f8 100644 --- a/ui/js/component/header/index.js +++ b/ui/js/component/header/index.js @@ -11,6 +11,8 @@ import { } from 'actions/app' import { doSearchContent, + doActivateSearch, + doDeactivateSearch, } from 'actions/search' import Header from './view' @@ -22,6 +24,8 @@ const select = (state) => ({ const perform = (dispatch) => ({ navigate: (path) => dispatch(doNavigate(path)), search: (query) => dispatch(doSearchContent(query)), + activateSearch: () => dispatch(doActivateSearch()), + deactivateSearch: () => setTimeout(() => { dispatch(doDeactivateSearch()) }, 10), }) export default connect(select, perform)(Header) diff --git a/ui/js/constants/action_types.js b/ui/js/constants/action_types.js index f00739ade..91c2593dc 100644 --- a/ui/js/constants/action_types.js +++ b/ui/js/constants/action_types.js @@ -5,8 +5,6 @@ export const CLOSE_MODAL = 'CLOSE_MODAL' export const OPEN_DRAWER = 'OPEN_DRAWER' export const CLOSE_DRAWER = 'CLOSE_DRAWER' -export const START_SEARCH = 'START_SEARCH' - export const DAEMON_READY = 'DAEMON_READY' // Upgrades @@ -63,3 +61,5 @@ export const DELETE_FILE_COMPLETED = 'DELETE_FILE_COMPLETED' export const SEARCH_STARTED = 'SEARCH_STARTED' export const SEARCH_COMPLETED = 'SEARCH_COMPLETED' export const SEARCH_CANCELLED = 'SEARCH_CANCELLED' +export const ACTIVATE_SEARCH = 'ACTIVATE_SEARCH' +export const DEACTIVATE_SEARCH = 'DEACTIVATE_SEARCH' diff --git a/ui/js/page/discover/index.js b/ui/js/page/discover/index.js index e279ff4d6..bb2d97e49 100644 --- a/ui/js/page/discover/index.js +++ b/ui/js/page/discover/index.js @@ -12,6 +12,7 @@ import { selectIsSearching, selectSearchQuery, selectCurrentSearchResults, + selectSearchActivated, } from 'selectors/search' import DiscoverPage from './view' @@ -20,6 +21,7 @@ const select = (state) => ({ isSearching: selectIsSearching(state), query: selectSearchQuery(state), results: selectCurrentSearchResults(state), + searchActive: selectSearchActivated(state), }) const perform = (dispatch) => ({ diff --git a/ui/js/page/discover/view.jsx b/ui/js/page/discover/view.jsx index 82151ccd9..e668855d2 100644 --- a/ui/js/page/discover/view.jsx +++ b/ui/js/page/discover/view.jsx @@ -61,4 +61,22 @@ let DiscoverPage = React.createClass({ } }) +// const DiscoverPage = (props) => { +// const { +// isSearching, +// query, +// results, +// searchActive, +// } = props +// +// return ( +//
+// { (!searchActive || (!isSearching && !query)) && } +// { searchActive && isSearching ? : null } +// { searchActive && !isSearching && query && results.length ? : null } +// { searchActive && !isSearching && query && !results.length ? : null } +//
+// ); +// } + export default DiscoverPage; \ No newline at end of file diff --git a/ui/js/reducers/search.js b/ui/js/reducers/search.js index 50a38966f..24cd757f6 100644 --- a/ui/js/reducers/search.js +++ b/ui/js/reducers/search.js @@ -41,6 +41,18 @@ reducers[types.SEARCH_CANCELLED] = function(state, action) { }) } +reducers[types.ACTIVATE_SEARCH] = function(state, action) { + return Object.assign({}, state, { + activated: true, + }) +} + +reducers[types.DEACTIVATE_SEARCH] = function(state, action) { + return Object.assign({}, state, { + activated: false, + }) +} + export default function reducer(state = defaultState, action) { const handler = reducers[action.type]; if (handler) return handler(state, action); diff --git a/ui/js/selectors/search.js b/ui/js/selectors/search.js index 240a4b6bc..b5f7bc1a4 100644 --- a/ui/js/selectors/search.js +++ b/ui/js/selectors/search.js @@ -27,3 +27,8 @@ export const selectCurrentSearchResults = createSelector( selectSearchResultsByQuery, (query, byQuery) => byQuery[query] || [] ) + +export const selectSearchActivated = createSelector( + _selectState, + (state) => !!state.activated +)