mirror of
https://github.com/fullstack-cash/explorer.fullstack.cash.git
synced 2026-09-21 16:52:05 -07:00
Merge pull request #2 from FullStack-cash/dh-fix-appid-filter
fix(filter): appId filter should persist through refresh
This commit is contained in:
+23
-17
@@ -19,7 +19,10 @@ class Explorer extends React.Component {
|
|||||||
data: [],
|
data: [],
|
||||||
entries: [],
|
entries: [],
|
||||||
entryData: null,
|
entryData: null,
|
||||||
addId: ''
|
addId: '',
|
||||||
|
endpoint: `${SERVER}entry/all/${0}`,
|
||||||
|
isFiltered: false,
|
||||||
|
inFetch: true
|
||||||
}
|
}
|
||||||
|
|
||||||
this.firstColumns = [
|
this.firstColumns = [
|
||||||
@@ -47,7 +50,7 @@ class Explorer extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { data, entryData } = _this.state
|
const { data, entryData, isFiltered, appId, inFetch } = _this.state
|
||||||
return (
|
return (
|
||||||
<Content
|
<Content
|
||||||
title='P2WDB Explorer'
|
title='P2WDB Explorer'
|
||||||
@@ -56,7 +59,7 @@ class Explorer extends React.Component {
|
|||||||
>
|
>
|
||||||
<Row>
|
<Row>
|
||||||
{!entryData && (
|
{!entryData && (
|
||||||
<Box title='Search By Appid' className='text-center'>
|
<Box loaded={!inFetch} title='Search By Appid' className='text-center'>
|
||||||
<Text
|
<Text
|
||||||
id='appId'
|
id='appId'
|
||||||
name='appId'
|
name='appId'
|
||||||
@@ -66,7 +69,7 @@ class Explorer extends React.Component {
|
|||||||
onChange={this.handleUpdate}
|
onChange={this.handleUpdate}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
text='Search'
|
text={isFiltered && !appId ? 'Search All' : 'Search'}
|
||||||
type='primary'
|
type='primary'
|
||||||
className='btn-lg btn-close-entry mr-1 ml-1 mt-1'
|
className='btn-lg btn-close-entry mr-1 ml-1 mt-1'
|
||||||
onClick={_this.handleSearchByAppId}
|
onClick={_this.handleSearchByAppId}
|
||||||
@@ -127,16 +130,19 @@ class Explorer extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// REST petition to Get data fron the pw2db
|
// REST petition to Get data fron the pw2db
|
||||||
async getEntries () {
|
async getEntries (endpoint) {
|
||||||
try {
|
try {
|
||||||
|
const url = endpoint || _this.state.endpoint
|
||||||
|
// console.log(`url : ${url}`)
|
||||||
const options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: `${SERVER}entry/all/${0}`,
|
url: url,
|
||||||
data: {}
|
data: {}
|
||||||
}
|
}
|
||||||
const result = await axios.request(options)
|
const result = await axios.request(options)
|
||||||
_this.setState({
|
_this.setState({
|
||||||
entries: result.data.data
|
entries: result.data.data,
|
||||||
|
inFetch: false
|
||||||
})
|
})
|
||||||
return result.data.data
|
return result.data.data
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -234,21 +240,21 @@ class Explorer extends React.Component {
|
|||||||
async handleSearchByAppId () {
|
async handleSearchByAppId () {
|
||||||
try {
|
try {
|
||||||
const { appId } = _this.state
|
const { appId } = _this.state
|
||||||
let entries
|
let endpoint
|
||||||
|
let isFiltered = true
|
||||||
if (!appId) {
|
if (!appId) {
|
||||||
entries = await _this.getEntries()
|
endpoint = `${SERVER}entry/all/${0}`
|
||||||
|
isFiltered = false
|
||||||
} else {
|
} else {
|
||||||
const options = {
|
endpoint = `${SERVER}entry/appid/${appId}`
|
||||||
method: 'GET',
|
|
||||||
url: `${SERVER}entry/appid/${appId}`
|
|
||||||
}
|
|
||||||
const result = await axios.request(options)
|
|
||||||
entries = result.data.data
|
|
||||||
}
|
}
|
||||||
|
// save the last called endpoint for intervall calls
|
||||||
_this.setState({
|
_this.setState({
|
||||||
entries
|
endpoint,
|
||||||
|
isFiltered,
|
||||||
|
inFetch: true
|
||||||
})
|
})
|
||||||
|
const entries = await _this.getEntries(endpoint)
|
||||||
_this.generateDataTable(entries)
|
_this.generateDataTable(entries)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(error)
|
console.warn(error)
|
||||||
|
|||||||
Reference in New Issue
Block a user