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,17 +11,42 @@ interface State {
|
||||||
searching: Boolean;
|
searching: Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSearchURL({state: { searchParams }}, key) {
|
class SortableLink extends Component {
|
||||||
let page, direction;
|
render({ sortKey, state: { searchParams } }) {
|
||||||
if (key === searchParams.sort_key) {
|
return <span>
|
||||||
page = searchParams.page;
|
<a href={this.buildSearchURL(sortKey, searchParams)}>
|
||||||
direction = searchParams.sort_dir === "Asc" ? "Desc" : "Asc";
|
{sortKey}
|
||||||
} else {
|
{this.renderIcon(sortKey, searchParams)}
|
||||||
page = 1;
|
</a>
|
||||||
direction = "Desc";
|
</span>;
|
||||||
}
|
}
|
||||||
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 <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