@@ -9,6 +9,7 @@ import { Input } from '../../components/input'
99import InfiniteScroll from 'react-infinite-scroll-component'
1010import { renderMediaType } from '../../components/media-types'
1111import './style.css'
12+ import { last } from 'lodash'
1213
1314const axios = require ( 'axios' )
1415const ls = require ( 'local-storage' )
@@ -174,7 +175,7 @@ async function fetchGLB(offset) {
174175async function fetchInteractive ( offset ) {
175176 const { errors, data } = await fetchGraphQL ( `
176177 query InteractiveObjkts {
177- hic_et_nunc_token(where: { mime: {_in : [ "application/x-directory" ]}, supply : { _neq : 0 } }, limit : 15, offset : ${ offset } , order_by: {id: desc}) {
178+ hic_et_nunc_token(where: { mime: {_in : [ "application/x-directory", "image/svg+xml" ]}, supply : { _neq : 0 } }, limit : 15, offset : ${ offset } , order_by: {id: desc}) {
178179 id
179180 artifact_uri
180181 display_uri
@@ -341,6 +342,7 @@ async function fetchRandomObjkts() {
341342}
342343
343344async function fetchDay ( day , offset ) {
345+ console . log ( day )
344346 const { errors, data } = await fetchGraphQL ( `query dayTrades {
345347 hic_et_nunc_trade(where: {timestamp: {_gte: "${ day } "}}, order_by: {swap: {price: desc}}, limit : 15, offset : ${ offset } ) {
346348 timestamp
@@ -370,6 +372,38 @@ async function fetchDay(day, offset) {
370372
371373}
372374
375+ async function fetchSales ( offset ) {
376+ console . log ( offset )
377+ const { errors, data } = await fetchGraphQL ( `
378+ query sales {
379+ hic_et_nunc_trade(order_by: {timestamp: desc}, limit : 15, offset : ${ offset } ) {
380+ timestamp
381+ swap {
382+ price
383+ }
384+ token {
385+ artifact_uri
386+ display_uri
387+ id
388+ mime
389+ }
390+ }
391+ }` , 'sales' , { } )
392+
393+ if ( errors ) {
394+ console . log ( errors )
395+ }
396+
397+ let result = [ ]
398+
399+ try {
400+ result = data . hic_et_nunc_trade
401+ } catch ( e ) { }
402+
403+ return result
404+
405+ }
406+
373407async function fetchSubjkts ( subjkt ) {
374408 //console.log(subjkt)
375409 const { errors, data } = await fetchGraphQL ( `
@@ -464,6 +498,8 @@ async function fetchHdao(offset) {
464498 return result
465499}
466500
501+
502+
467503export class Search extends Component {
468504 static contextType = HicetnuncContext
469505
@@ -476,15 +512,17 @@ export class Search extends Component {
476512 prev : '' ,
477513 reset : false ,
478514 flag : false ,
515+ lastId : undefined ,
479516 tags : [
480517 { id : 0 , value : '○' } ,
481- { id : 1 , value : 'random' } ,
482- { id : 2 , value : 'glb' } ,
483- { id : 3 , value : 'music' } ,
484- { id : 4 , value : 'interactive' } ,
485- { id : 5 , value : 'gif' } ,
486- { id : 6 , value : '1D' } ,
487- { id : 7 , value : '1W' } ,
518+ { id : 1 , value : 'latest sales' } ,
519+ { id : 2 , value : 'latest mints' } ,
520+ { id : 3 , value : 'glb' } ,
521+ { id : 4 , value : 'music' } ,
522+ { id : 5 , value : 'interactive' } ,
523+ { id : 6 , value : 'gif' } ,
524+ { id : 7 , value : '1D' } ,
525+ { id : 8 , value : '1W' }
488526 /* { id: 4, value: 'illustration' }, */
489527 /* { id: 5, value: 'gif' } */
490528
@@ -588,6 +626,19 @@ export class Search extends Component {
588626 this . setState ( { feed : [ ...this . state . feed , ...( await fetchTag ( this . state . search , this . state . feed [ this . state . feed . length - 1 ] . id ) ) ] } )
589627 }
590628
629+ if ( e == 'latest sales' ) {
630+ let tokens = await fetchSales ( this . state . offset + 250 )
631+ tokens = tokens . map ( e => e . token )
632+ tokens = _ . uniqBy ( tokens , 'id' )
633+
634+ this . setState ( { feed : _ . uniqBy ( [ ...this . state . feed , ...tokens ] , 'id' ) } )
635+ }
636+
637+ if ( e == 'latest mints' ) {
638+ this . setState ( { feed : [ ...this . state . feed , ...( await fetchFeed ( 999999 || this . state . lastId ) ) ] } )
639+ this . setState ( { lastId : Math . min . apply ( Math , this . state . feed . map ( e => e . id ) ) } )
640+ }
641+
591642 this . setState ( { reset : false } )
592643
593644 //this.setState({ feed : this.state.feed })
0 commit comments