@@ -13,24 +13,13 @@ import TableCell from "@material-ui/core/TableCell";
1313import TableRow from "@material-ui/core/TableRow" ;
1414import Typography from "@material-ui/core/Typography" ;
1515import DeleteForeverIcon from "@material-ui/icons/DeleteForever" ;
16- import axios , { AxiosResponse } from "axios" ;
1716import nullthrows from "nullthrows" ;
1817import React from "react" ;
18+ import { FileDetailsAPIResponse , withAPI , WithAPIProps } from "../api" ;
1919import { renderTime } from "../utils" ;
2020import FilePreview from "./FilePreview" ;
2121
22- interface FileDetailsAPIResponse {
23- filename : string ;
24- path : string ;
25- bed_size_mm : [ number , number , number ] ;
26- height_mm : number ;
27- layer_count : number ;
28- layer_height_mm : number ;
29- resolution : [ number , number ] ;
30- print_time_secs : number ;
31- }
32-
33- interface FileDetailsProps {
22+ interface FileDetailsProps extends WithAPIProps {
3423 filename : string ;
3524 path : string ;
3625}
@@ -46,14 +35,13 @@ class FileDetails extends React.Component<FileDetailsProps, FileDetailsState> {
4635 } ;
4736
4837 async componentDidMount ( ) : Promise < void > {
49- const response : AxiosResponse < FileDetailsAPIResponse > = await axios . get (
50- "api/file_details" ,
51- { params : { filename : this . props . path } }
52- ) ;
53- this . setState ( {
54- isLoading : false ,
55- data : response . data ,
56- } ) ;
38+ const response = await this . props . api . fileDetails ( this . props . path ) ;
39+ if ( response ) {
40+ this . setState ( {
41+ isLoading : false ,
42+ data : response ,
43+ } ) ;
44+ }
5745 }
5846
5947 _getTableContent ( data : FileDetailsAPIResponse ) : Array < [ string , string ] > {
@@ -115,6 +103,8 @@ const useStyles = makeStyles({
115103 } ,
116104} ) ;
117105
106+ const FileDetailsWithAPI = withAPI ( FileDetails ) ;
107+
118108export default function FileDetailsDialog (
119109 props : {
120110 filename : string ;
@@ -168,7 +158,7 @@ export default function FileDetailsDialog(
168158 </ Dialog >
169159 </ DialogTitle >
170160 < DialogContent style = { { padding : 0 } } dividers >
171- < FileDetails filename = { props . filename } path = { props . path } />
161+ < FileDetailsWithAPI filename = { props . filename } path = { props . path } />
172162 </ DialogContent >
173163 < DialogActions >
174164 < Button onClick = { props . onCancel } color = "primary" >
0 commit comments