1
1
import React , { Component } from 'react' ;
2
2
import '../App.css'
3
3
import axios from 'axios' ;
4
+ import githubIcon from '../icon/github.svg'
5
+ import fullscreenIcon from '../icon/fullscreen.svg'
4
6
5
7
import { CLIENT_ID , CLIENT_SECRET , PROXY , ACCESS_TOKEN } from '../utils/constant.js' ;
6
8
import { queryParse , axiosJSON , axiosGithub } from '../utils/helper' ;
7
9
10
+ // Material Design
11
+ import PropTypes from 'prop-types' ;
12
+ import { withStyles } from '@material-ui/core/styles' ;
13
+ import IconButton from '@material-ui/core/IconButton' ;
14
+ import DeleteIcon from '@material-ui/icons/Delete' ;
15
+ import Tooltip from '@material-ui/core/Tooltip' ;
16
+
17
+
18
+
19
+ const styles = theme => ( {
20
+ button : {
21
+ margin : theme . spacing . unit ,
22
+ borderRadius : 0 ,
23
+ } ,
24
+ } ) ;
25
+
8
26
9
27
class Navbar extends Component {
10
28
constructor ( props ) {
@@ -42,8 +60,6 @@ class Navbar extends Component {
42
60
console . log ( this . state . title ) ;
43
61
}
44
62
45
-
46
-
47
63
login = ( ) => {
48
64
window . location . href = `https://github.com/login/oauth/authorize?client_id=${ CLIENT_ID } &scope=public_repo` ;
49
65
}
@@ -88,10 +104,13 @@ class Navbar extends Component {
88
104
//commit the file
89
105
90
106
commitFile = async ( ) => {
107
+
108
+ console . log ( this . props . content ) ;
91
109
try {
92
110
const response = await axiosGithub . put ( `/repos/zhning12/markdown_example/contents/${ this . state . title } .md` , {
93
111
"message" : "I am the commit message" ,
94
- "content" : btoa ( this . state . content )
112
+ // "content": btoa(this.state.content)
113
+ "content" : btoa ( this . props . content )
95
114
} ) ;
96
115
console . log ( response ) ;
97
116
} catch ( error ) {
@@ -100,16 +119,24 @@ class Navbar extends Component {
100
119
}
101
120
102
121
render ( ) {
122
+ const { classes } = this . props ;
103
123
return (
104
124
< div className = "navi-bar" >
105
125
< div className = "left-nav" > </ div >
106
126
< div className = "right-nav" > </ div >
127
+ < Tooltip title = "Log in GitHub" enterDelay = { 500 } leaveDelay = { 200 } >
128
+ < IconButton className = { classes . button } onClick = { this . login } >
129
+ < img src = { githubIcon } alt = "log in" > </ img >
130
+ </ IconButton >
131
+ </ Tooltip >
107
132
108
- < button onClick = { this . login } > 点击登录</ button >
133
+ < IconButton className = { classes . button } aria-label = "Delete" >
134
+ < DeleteIcon />
135
+ </ IconButton >
109
136
110
- < button onClick = { this . fullScreen } id = "goFS" >
111
- { this . state . isFullScreen ? '取消全屏' : '全屏' }
112
- </ button >
137
+ < IconButton className = { classes . button } onClick = { this . fullScreen } id = "goFS" >
138
+ < img src = { fullscreenIcon } alt = "full screen" > </ img >
139
+ </ IconButton >
113
140
114
141
< button onClick = { this . createRepo } id = "createRepo" >
115
142
Create a New Repo
@@ -133,4 +160,8 @@ class Navbar extends Component {
133
160
}
134
161
}
135
162
136
- export default Navbar ;
163
+ Navbar . propTypes = {
164
+ classes : PropTypes . object . isRequired ,
165
+ } ;
166
+
167
+ export default withStyles ( styles ) ( Navbar ) ;
0 commit comments