File tree 12 files changed +375
-24
lines changed
github-app/src/pages/IssueDetail
12 files changed +375
-24
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import PkgTabs from '@site/src/components/PkgTabs';
10
10
import GenericsTabs from '@site/src /components/GenericsTabs';
11
11
import ConditionalDependencies from '../shared/\_ conditional_dependencies.mdx';
12
12
import TypeScriptEditor from '@site/src /components/TypeScriptEditor';
13
+ import StackBlitz from '@site/src /components/StackBlitz';
13
14
14
15
<head >
15
16
<title >useDLE() - [D]ata [L]oading [E]rror React State </title >
@@ -309,3 +310,13 @@ export default function ArticleList({ page }: { page: string }) {
309
310
```
310
311
311
312
</TypeScriptEditor >
313
+
314
+ ### Github Reactions
315
+
316
+ ` useDLE() ` allows us to declaratively fetch reactions on any issue page the moment we navigate to it. This allows
317
+ us to not block the issues page from showing if the reactions are not completed loading.
318
+
319
+ It's usually better to wrap cases like this in new [ Suspense Boundaries] ( ../getting-started/data-dependency.md#boundaries ) .
320
+ However, our component library ` ant design ` does not allow this.
321
+
322
+ <StackBlitz app =" github-app " file =" src/resources/Reaction.tsx,src/pages/IssueDetail/index.tsx " view =" editor " initialpath =" /reactive/data-client/issue/1113 " height ={750} />
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ title: useFetch()
4
4
5
5
import GenericsTabs from '@site/src /components/GenericsTabs';
6
6
import ConditionalDependencies from '../shared/\_ conditional_dependencies.mdx';
7
- import StackBlitz from '@site/src /components/StackBlitz';
8
7
9
8
<head >
10
9
<title >useFetch() - Declarative fetch triggers for React </title >
@@ -78,15 +77,3 @@ function useFetch<
78
77
```
79
78
80
79
</GenericsTabs >
81
-
82
- ## Examples
83
-
84
- ### Github Reactions
85
-
86
- ` useFetch() ` allows us to declaratively fetch reactions on any issue page the moment we navigate to it. This allows
87
- us to not block the issues page from showing if the reactions are not completed loading.
88
-
89
- It's usually better to wrap cases like this in new [ Suspense Boundaries] ( ../getting-started/data-dependency.md#boundaries ) .
90
- However, our component library ` ant design ` does not allow this.
91
-
92
- <StackBlitz app =" github-app " file =" src/resources/Reaction.tsx,src/pages/IssueDetail/index.tsx " view =" editor " initialpath =" /reactive/data-client/issue/1113 " height ={750} />
Original file line number Diff line number Diff line change 29
29
"@linaria/core" : " *" ,
30
30
"@linaria/react" : " *" ,
31
31
"@linaria/shaker" : " *" ,
32
+ "@types/d3" : " ^7" ,
32
33
"@types/react" : " *" ,
33
34
"@types/react-dom" : " *" ,
34
35
"react-refresh" : " *" ,
45
46
"@data-client/react" : " ^0.11.0" ,
46
47
"@data-client/redux" : " ^0.11.0" ,
47
48
"@data-client/rest" : " ^0.11.0" ,
49
+ "d3" : " ^7.9.0" ,
48
50
"history" : " *" ,
49
51
"react" : " ^18.2.0" ,
50
52
"react-dom" : " ^18.2.0" ,
Original file line number Diff line number Diff line change
1
+ import { useDLE } from '@data-client/react' ;
2
+ import { useMemo } from 'react' ;
3
+ import { getCandles } from 'resources/Candles' ;
4
+
5
+ import { formatPrice } from '../../components/formatPrice' ;
6
+
7
+ export default function AssetChart ( { product_id } : Props ) {
8
+ const { data : candles , loading } = useDLE ( getCandles , { product_id } ) ;
9
+ // Don't block page from loading
10
+ // TODO: put correct height item here
11
+ if ( loading || ! candles ) return < span > </ span > ;
12
+
13
+ return < span > </ span > ;
14
+ }
15
+
16
+ interface Props {
17
+ product_id : string ;
18
+ }
Original file line number Diff line number Diff line change 1
1
import { useSuspense } from '@data-client/react' ;
2
2
import { CurrencyResource } from 'resources/Currency' ;
3
3
4
+ import AssetChart from './AssetChart' ;
4
5
import AssetPrice from './AssetPrice' ;
5
6
import Stats from './Stats' ;
6
7
@@ -11,6 +12,7 @@ export default function AssetDetail({ id }: { id: string }) {
11
12
< h1 > { currency . name } </ h1 >
12
13
< AssetPrice product_id = { `${ currency . id } -USD` } />
13
14
< Stats id = { `${ currency . id } -USD` } />
15
+ < AssetChart product_id = { `${ currency . id } -USD` } />
14
16
</ >
15
17
) ;
16
18
}
Original file line number Diff line number Diff line change
1
+ import { RestEndpoint } from '@data-client/rest' ;
2
+
3
+ // docs: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductcandles
4
+ export const getCandles = new RestEndpoint ( {
5
+ urlPrefix : 'https://api.exchange.coinbase.com' ,
6
+ path : '/products/:product_id/candles' ,
7
+ searchParams : { } as {
8
+ granularity ?: 60 | 300 | 900 | 3600 | 21600 | 86400 ;
9
+ start ?: string | number ;
10
+ end ?: string | number ;
11
+ } ,
12
+ process ( value : CandleTuple [ ] ) {
13
+ return value . map ( candle => ( {
14
+ timestamp : candle [ 0 ] ,
15
+ price_open : candle [ 3 ] ,
16
+ } ) ) ;
17
+ } ,
18
+ } ) ;
19
+
20
+ type CandleTuple = [
21
+ timestamp : number ,
22
+ price_low : number ,
23
+ price_high : number ,
24
+ price_open : number ,
25
+ price_close : number ,
26
+ ] ;
Original file line number Diff line number Diff line change @@ -43,12 +43,9 @@ export const queryProduct = new schema.Query(
43
43
product => product . quote_currency === quote_currency ,
44
44
) ;
45
45
46
- sorted = sorted . sort ( ( a , b ) => {
46
+ return sorted . sort ( ( a , b ) => {
47
47
return b . stats . volume_30day - a . stats . volume_30day ;
48
48
} ) ;
49
- const btc = sorted . find ( product => product . base_currency === 'BTC' ) ;
50
- if ( btc ) sorted . unshift ( btc ) ;
51
- return sorted ;
52
49
} ,
53
50
) ;
54
51
Original file line number Diff line number Diff line change 1
1
import { Route } from '@anansi/router' ;
2
2
import { Controller } from '@data-client/react' ;
3
+ import { getCandles } from 'resources/Candles' ;
3
4
import { CurrencyResource } from 'resources/Currency' ;
4
5
import { StatsResource } from 'resources/Stats' ;
5
6
import { getTicker } from 'resources/Ticker' ;
@@ -22,6 +23,7 @@ export const routes: Route<Controller>[] = [
22
23
component : lazyPage ( 'AssetDetail' ) ,
23
24
async resolveData ( controller , { id } ) {
24
25
const product_id = `${ id } -USD` ;
26
+ controller . fetchIfStale ( getCandles , { product_id } ) ;
25
27
await Promise . allSettled ( [
26
28
controller . fetchIfStale ( getTicker , { product_id } ) ,
27
29
controller . fetchIfStale ( CurrencyResource . get , { id } ) ,
Original file line number Diff line number Diff line change 1
1
import { Link } from '@anansi/router' ;
2
- import { useSuspense , useFetch , useCache } from '@data-client/react' ;
2
+ import { useSuspense , useCache , useDLE } from '@data-client/react' ;
3
3
import { Card , Avatar , Popover } from 'antd' ;
4
4
import { Tag } from 'antd' ;
5
5
import Boundary from 'Boundary' ;
@@ -25,9 +25,10 @@ const { Meta } = Card;
25
25
26
26
function IssueDetail ( { number, repo, owner } : Props ) {
27
27
const params = { number, repo, owner } ;
28
- useFetch ( ReactionResource . getList , params ) ;
28
+ const {
29
+ data : { results : reactions } ,
30
+ } = useDLE ( ReactionResource . getList , params ) ;
29
31
const issue = useSuspense ( IssueResource . get , params ) ;
30
- const { results : reactions } = useCache ( ReactionResource . getList , params ) ;
31
32
const currentUser = useCache ( UserResource . current ) ;
32
33
33
34
const actions : JSX . Element [ ] = useMemo ( ( ) => {
Original file line number Diff line number Diff line change 37
37
},
38
38
{
39
39
"type" : " doc" ,
40
- "id" : " api/Invalidate "
40
+ "id" : " api/Query "
41
41
},
42
42
{
43
43
"type" : " doc" ,
44
44
"id" : " api/All"
45
45
},
46
46
{
47
47
"type" : " doc" ,
48
- "id" : " api/Query "
48
+ "id" : " api/Invalidate "
49
49
},
50
50
{
51
51
"type" : " doc" ,
Original file line number Diff line number Diff line change
1
+ /img/client-logo.svg
2
+ Cross-Origin-Resource-Policy: cross-origin
3
+ Access-Control-Allow-Origin: *
4
+ Cross-Origin-Embedder-Policy: credentialless
5
+
6
+ /img/cancel.svg
7
+ Cross-Origin-Resource-Policy: cross-origin
8
+ Access-Control-Allow-Origin: *
9
+ Cross-Origin-Embedder-Policy: credentialless
You can’t perform that action at this time.
0 commit comments