@@ -24,11 +24,18 @@ export const Feeds = ({ type = 0 }) => {
2424 const [ items , setItems ] = useState ( [ ] )
2525 const [ count , setCount ] = useState ( 0 )
2626 const [ lastId , setId ] = useState ( 999999 )
27+ const [ offset , setOffset ] = useState ( 0 )
2728 const [ hasMore , setHasMore ] = useState ( true )
2829 const startTime = customFloor ( Date . now ( ) , ONE_MINUTE_MILLIS )
29- const loadMore = ( ) => {
30- setCount ( count + 1 )
31- }
30+ const loadMore = async ( ) => {
31+
32+ if ( type === 1 ) {
33+ await getHdaoFeed ( )
34+ }
35+ if ( type === 2 ) await getRandomFeed ( )
36+ if ( type === 3 ) getLatest ( Math . min . apply ( Math , items . map ( e => e . id ) ) )
37+
38+ }
3239
3340 useEffect ( async ( ) => {
3441 if ( error ) {
@@ -51,42 +58,20 @@ export const Feeds = ({ type = 0 }) => {
5158 setError ( true )
5259 } )
5360 } else if ( type === 1 ) {
54- GethDAOFeed ( { counter : count } )
55- . then ( ( result ) => {
56- const next = items . concat ( result )
57- setItems ( next )
58-
59- // if original returns less than 10, then there's no more data coming from API
60- if ( result . length < 10 ) {
61- setHasMore ( false )
62- }
63- } )
64- . catch ( ( e ) => {
65- setError ( true )
66- } )
61+ await getHdaoFeed ( )
6762 } else if ( type === 2 ) {
68- GetRandomFeed ( { counter : count } )
69- . then ( ( result ) => {
70- // filtered isn't guaranteed to always be 10. if we're filtering they might be less.
71- const next = items . concat ( result )
7263
73- next . map ( e => console . log ( e ) )
74- setItems ( next )
64+ await getRandomFeed ( )
7565
76- // if original returns less than 10, then there's no more data coming from API
77- if ( result . length < 10 ) {
78- setHasMore ( false )
79- }
80- } )
81- . catch ( ( e ) => {
82- setError ( true )
83- } )
8466 } else if ( type === 3 ) {
8567
8668 let result = await axios . post ( process . env . REACT_APP_GRAPHQL_FEED , { lastId : lastId } ) . then ( res => res . data )
87- console . log ( result )
88- const next = items . concat ( result )
69+
70+ const next = result . concat ( result )
8971 setItems ( next )
72+ if ( result . length < 10 ) {
73+ setHasMore ( false )
74+ }
9075/* GetFeaturedFeed({ counter: count, max_time: startTime })
9176 .then((result) => {
9277 // filtered isn't guaranteed to always be 10. if we're filtering they might be less.
@@ -104,6 +89,32 @@ export const Feeds = ({ type = 0 }) => {
10489 }
10590 } , [ count , type ] )
10691
92+ const getLatest = async ( id ) => {
93+
94+ let result = await axios . post ( process . env . REACT_APP_GRAPHQL_FEED , { lastId : id } ) . then ( res => res . data )
95+ const next = items . concat ( result )
96+ setItems ( next )
97+ if ( result . length < 10 ) {
98+ setHasMore ( false )
99+ }
100+ }
101+
102+ const getHdaoFeed = async ( ) => {
103+
104+ let result = await axios . post ( process . env . REACT_APP_GRAPHQL_HDAO , { offset : offset } ) . then ( res => res . data )
105+ setOffset ( offset + 50 )
106+ const next = items . concat ( result )
107+ setItems ( next )
108+
109+ }
110+
111+ const getRandomFeed = async ( ) => {
112+ let result = await axios . post ( process . env . REACT_APP_GRAPHQL_RANDOM ) . then ( res => res . data )
113+ setOffset ( offset + 50 )
114+ const next = items . concat ( result )
115+ setItems ( next )
116+ }
117+
107118 return (
108119 < Page title = "" >
109120 < InfiniteScroll
0 commit comments