forked from newthuhole/hole_thu_frontend
search query paging
This commit is contained in:
14
src/Flows.js
14
src/Flows.js
@@ -13,7 +13,6 @@ import {API, PKUHELPER_ROOT} from './flows_api';
|
||||
const IMAGE_BASE=PKUHELPER_ROOT+'services/pkuhole/images/';
|
||||
const AUDIO_BASE=PKUHELPER_ROOT+'services/pkuhole/audios/';
|
||||
|
||||
const SEARCH_PAGESIZE=50;
|
||||
const CLICKABLE_TAGS={a: true, audio: true};
|
||||
const PREVIEW_REPLY_COUNT=10;
|
||||
const QUOTE_BLACKLIST=['23333','233333','66666','666666','10086','10000','100000','99999','999999','55555','555555'];
|
||||
@@ -711,17 +710,20 @@ export class Flow extends PureComponent {
|
||||
})
|
||||
.catch(failed);
|
||||
} else if(this.state.mode==='search') {
|
||||
API.get_search(SEARCH_PAGESIZE*page,this.state.search_param,this.props.token)
|
||||
API.get_search(page,this.state.search_param,this.props.token)
|
||||
.then((json)=>{
|
||||
const finished=json.data.length<SEARCH_PAGESIZE;
|
||||
this.setState({
|
||||
const finished=json.data.length===0;
|
||||
this.setState((prev,props)=>({
|
||||
chunks: {
|
||||
title: 'Result for "'+this.state.search_param+'"',
|
||||
data: json.data,
|
||||
data: prev.chunks.data.concat(json.data.filter((x)=>(
|
||||
prev.chunks.data.length===0 ||
|
||||
!(prev.chunks.data.slice(-100).some((p)=>p.pid===x.pid))
|
||||
))),
|
||||
},
|
||||
mode: finished ? 'search_finished' : 'search',
|
||||
loading_status: 'done',
|
||||
});
|
||||
}));
|
||||
})
|
||||
.catch(failed);
|
||||
} else if(this.state.mode==='single') {
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, {Component, PureComponent} from 'react';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import {API_BASE,SafeTextarea} from './Common';
|
||||
import {MessageViewer} from './Message';
|
||||
import {API_VERSION_PARAM,PKUHELPER_ROOT,API,get_json} from './flows_api';
|
||||
import {API_VERSION_PARAM, PKUHELPER_ROOT, API, get_json, token_param} from './flows_api';
|
||||
|
||||
import './UserAction.css';
|
||||
|
||||
@@ -301,7 +301,7 @@ export class ReplyForm extends Component {
|
||||
data.append('pid',this.props.pid);
|
||||
data.append('text',this.state.text);
|
||||
data.append('user_token',this.props.token);
|
||||
fetch(API_BASE+'/api.php?action=docomment'+API_VERSION_PARAM(), {
|
||||
fetch(API_BASE+'/api.php?action=docomment'+token_param(this.props.token), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
@@ -381,7 +381,7 @@ export class PostForm extends Component {
|
||||
if(img)
|
||||
data.append('data',img);
|
||||
|
||||
fetch(API_BASE+'/api.php?action=dopost'+API_VERSION_PARAM(), {
|
||||
fetch(API_BASE+'/api.php?action=dopost'+token_param(this.props.token), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
|
||||
@@ -8,12 +8,14 @@ export function API_VERSION_PARAM() {
|
||||
}
|
||||
export {PKUHELPER_ROOT};
|
||||
|
||||
function token_param(token) {
|
||||
export function token_param(token) {
|
||||
return API_VERSION_PARAM()+(token ? ('&user_token='+token) : '');
|
||||
}
|
||||
|
||||
export {get_json};
|
||||
|
||||
const SEARCH_PAGESIZE=50;
|
||||
|
||||
export const API={
|
||||
load_replies: (pid,token,color_picker,cache_version)=>{
|
||||
pid=parseInt(pid);
|
||||
@@ -74,7 +76,7 @@ export const API={
|
||||
data.append('user_token',token);
|
||||
data.append('pid',pid);
|
||||
data.append('switch',attention ? '1' : '0');
|
||||
return fetch(API_BASE+'/api.php?action=attention'+API_VERSION_PARAM(), {
|
||||
return fetch(API_BASE+'/api.php?action=attention'+token_param(token), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
@@ -99,7 +101,7 @@ export const API={
|
||||
data.append('user_token',token);
|
||||
data.append('pid',pid);
|
||||
data.append('reason',reason);
|
||||
return fetch(API_BASE+'/api.php?action=report'+API_VERSION_PARAM(), {
|
||||
return fetch(API_BASE+'/api.php?action=report'+token_param(token), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
@@ -130,10 +132,11 @@ export const API={
|
||||
});
|
||||
},
|
||||
|
||||
get_search: (pagesize,keyword,token)=>{
|
||||
get_search: (page,keyword,token)=>{
|
||||
return fetch(
|
||||
API_BASE+'/api.php?action=search'+
|
||||
'&pagesize='+pagesize+
|
||||
'&pagesize='+SEARCH_PAGESIZE+
|
||||
'&page='+page+
|
||||
'&keywords='+encodeURIComponent(keyword)+
|
||||
token_param(token)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user