From 2362c4eddf9c69c2c8dd74e33d9755d7deda734b Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Fri, 3 Jul 2020 12:32:09 +0200 Subject: [PATCH] Fully working, needs polishing --- server/ui/src/Main.css | 4 ++ server/ui/src/components/search.tsx | 74 ++++++++++++++++------------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/server/ui/src/Main.css b/server/ui/src/Main.css index a381704..0385b6b 100644 --- a/server/ui/src/Main.css +++ b/server/ui/src/Main.css @@ -79,6 +79,10 @@ a::-moz-focus-inner { align-self: center; } +th .icon { + color: #333333; +} + .spinner { animation: spin 2s linear infinite; width: 20vw; diff --git a/server/ui/src/components/search.tsx b/server/ui/src/components/search.tsx index 9b1dfe6..c2cdfb0 100644 --- a/server/ui/src/components/search.tsx +++ b/server/ui/src/components/search.tsx @@ -1,4 +1,4 @@ -import { Component, linkEvent } from 'inferno'; +import { Component, render, linkEvent } from 'inferno'; import moment from 'moment'; import { endpoint } from '../env'; @@ -11,17 +11,42 @@ interface State { searching: Boolean; } -function buildSearchURL({state: { searchParams }}, key) { - let page, direction; - if (key === searchParams.sort_key) { - page = searchParams.page; - direction = searchParams.sort_dir === "Asc" ? "Desc" : "Asc"; - } else { - page = 1; - direction = "Desc"; +class SortableLink extends Component { + render({ sortKey, state: { searchParams } }) { + return + + {sortKey} + {this.renderIcon(sortKey, searchParams)} + + ; } - return `/#/search/${searchParams.type_}/${searchParams.q}/${page}/${key}/${direction}`; -} + + buildSearchURL(key, searchParams) { + let page, direction; + if (key === searchParams.sort_key) { + page = searchParams.page; + direction = searchParams.sort_dir === "Asc" ? "Desc" : "Asc"; + } else { + page = 1; + direction = "Desc"; + } + return `/#/search/${searchParams.type_}/${searchParams.q}/${page}/${key}/${direction}`; + } + + renderIcon(sortKey, searchParams) { + console.log("sortKey is", sortKey, "and params is", searchParams); + if (searchParams.sort_key !== sortKey) { + console.log("ret 1"); + return ""; + } + if (searchParams.sort_dir === "Asc") { + console.log("ret 2"); + return ; + } + console.log("ret 3"); + return l + } +) export class Search extends Component { state: State = { @@ -43,7 +68,6 @@ export class Search extends Component { } componentDidMount() { - console.log("loading page, got match", this.props.match.params); this.state.searchParams = { page: Number(this.props.match.params.page), q: this.props.match.params.q, @@ -57,7 +81,6 @@ export class Search extends Component { // Re-do search if the props have changed componentDidUpdate(lastProps: any) { if (lastProps.match && lastProps.match.params !== this.props.match.params) { - console.log("updating component with sort_key", this.props.match.params.sort_key); this.state.searchParams = { page: Number(this.props.match.params.page), q: this.props.match.params.q, @@ -132,34 +155,19 @@ export class Search extends Component { - - Name - + - - Size - + - - Seeds - + - - Leechers - + - - Scraped - +