Fully working, needs polishing
This commit is contained in:
parent
f571ec261c
commit
2362c4eddf
|
@ -79,6 +79,10 @@ a::-moz-focus-inner {
|
||||||
align-self: center;
|
align-self: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
th .icon {
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
.spinner {
|
.spinner {
|
||||||
animation: spin 2s linear infinite;
|
animation: spin 2s linear infinite;
|
||||||
width: 20vw;
|
width: 20vw;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, linkEvent } from 'inferno';
|
import { Component, render, linkEvent } from 'inferno';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import { endpoint } from '../env';
|
import { endpoint } from '../env';
|
||||||
|
@ -11,7 +11,17 @@ interface State {
|
||||||
searching: Boolean;
|
searching: Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSearchURL({state: { searchParams }}, key) {
|
class SortableLink extends Component {
|
||||||
|
render({ sortKey, state: { searchParams } }) {
|
||||||
|
return <span>
|
||||||
|
<a href={this.buildSearchURL(sortKey, searchParams)}>
|
||||||
|
{sortKey}
|
||||||
|
{this.renderIcon(sortKey, searchParams)}
|
||||||
|
</a>
|
||||||
|
</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildSearchURL(key, searchParams) {
|
||||||
let page, direction;
|
let page, direction;
|
||||||
if (key === searchParams.sort_key) {
|
if (key === searchParams.sort_key) {
|
||||||
page = searchParams.page;
|
page = searchParams.page;
|
||||||
|
@ -21,7 +31,22 @@ function buildSearchURL({state: { searchParams }}, key) {
|
||||||
direction = "Desc";
|
direction = "Desc";
|
||||||
}
|
}
|
||||||
return `/#/search/${searchParams.type_}/${searchParams.q}/${page}/${key}/${direction}`;
|
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 <svg class="icon icon-arrow-up d-none d-sm-inline mr-1"><use xlinkHref="#icon-arrow-up"></use></svg>;
|
||||||
|
}
|
||||||
|
console.log("ret 3");
|
||||||
|
return <svg class="icon icon-arrow-down mr-1"><use xlinkHref="#icon-arrow-down"></use></svg>l
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
export class Search extends Component<any, State> {
|
export class Search extends Component<any, State> {
|
||||||
state: State = {
|
state: State = {
|
||||||
|
@ -43,7 +68,6 @@ export class Search extends Component<any, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
console.log("loading page, got match", this.props.match.params);
|
|
||||||
this.state.searchParams = {
|
this.state.searchParams = {
|
||||||
page: Number(this.props.match.params.page),
|
page: Number(this.props.match.params.page),
|
||||||
q: this.props.match.params.q,
|
q: this.props.match.params.q,
|
||||||
|
@ -57,7 +81,6 @@ export class Search extends Component<any, State> {
|
||||||
// Re-do search if the props have changed
|
// Re-do search if the props have changed
|
||||||
componentDidUpdate(lastProps: any) {
|
componentDidUpdate(lastProps: any) {
|
||||||
if (lastProps.match && lastProps.match.params !== this.props.match.params) {
|
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 = {
|
this.state.searchParams = {
|
||||||
page: Number(this.props.match.params.page),
|
page: Number(this.props.match.params.page),
|
||||||
q: this.props.match.params.q,
|
q: this.props.match.params.q,
|
||||||
|
@ -132,34 +155,19 @@ export class Search extends Component<any, State> {
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="search-name-col">
|
<th class="search-name-col">
|
||||||
<a
|
<SortableLink sortKey="Name" state={this.state}/>
|
||||||
href={buildSearchURL(this, 'Name')}>
|
|
||||||
Name
|
|
||||||
</a>
|
|
||||||
</th>
|
</th>
|
||||||
<th class="text-right">
|
<th class="text-right">
|
||||||
<a
|
<SortableLink sortKey="Size" state={this.state}/>
|
||||||
href={buildSearchURL(this, 'Size')}>
|
|
||||||
Size
|
|
||||||
</a>
|
|
||||||
</th>
|
</th>
|
||||||
<th class="text-right">
|
<th class="text-right">
|
||||||
<a
|
<SortableLink sortKey="Seeders" state={this.state}/>
|
||||||
href={buildSearchURL(this, 'Seeders')}>
|
|
||||||
Seeds
|
|
||||||
</a>
|
|
||||||
</th>
|
</th>
|
||||||
<th class="text-right d-none d-md-table-cell">
|
<th class="text-right d-none d-md-table-cell">
|
||||||
<a
|
<SortableLink sortKey="Leechers" state={this.state}/>
|
||||||
href={buildSearchURL(this, 'Leechers')}>
|
|
||||||
Leechers
|
|
||||||
</a>
|
|
||||||
</th>
|
</th>
|
||||||
<th class="text-right d-none d-md-table-cell">
|
<th class="text-right d-none d-md-table-cell">
|
||||||
<a
|
<SortableLink sortKey="Date" state={this.state}/>
|
||||||
href={buildSearchURL(this, 'Date')}>
|
|
||||||
Scraped
|
|
||||||
</a>
|
|
||||||
</th>
|
</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Reference in New Issue