質問編集履歴
3
更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,25 +2,219 @@
|
|
2
2
|
|
3
3
|
cardHeaderのtitleにカーソルがあった時に、リンクがあるため色を変えようと思い、このようにかいたのですが、
|
4
4
|
```js
|
5
|
+
import React, { Component } from 'react'
|
6
|
+
import { Card, CardActions, CardHeader, CardText, CardTitle } from 'material-ui/Card'
|
7
|
+
import FlatButton from 'material-ui/FlatButton'
|
8
|
+
import { List } from 'material-ui/List'
|
9
|
+
import Dialog from 'material-ui/Dialog'
|
10
|
+
import Avatar from 'material-ui/Avatar'
|
11
|
+
import ChatIcon from 'material-ui/svg-icons/communication/chat-bubble-outline'
|
12
|
+
import Badge from 'material-ui/Badge'
|
13
|
+
import { withStyles } from 'material-ui/styles'
|
14
|
+
|
15
|
+
import Linkify from 'react-linkify'
|
16
|
+
import Timestamp from 'react-timestamp'
|
17
|
+
|
18
|
+
import firebase from 'firebase'
|
19
|
+
|
20
|
+
import CommentRef from './CommentRef'
|
21
|
+
import CommentForm from './CommentForm'
|
22
|
+
|
23
|
+
|
24
|
+
const myStyle = {
|
25
|
+
title: {
|
26
|
+
'&:hover': {
|
27
|
+
background: '#E0F7FA',
|
28
|
+
color:'white'
|
29
|
+
},
|
30
|
+
paddingTop:'0'
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
class PostRef extends Component {
|
35
|
+
constructor(props) {
|
36
|
+
super(props);
|
37
|
+
this.state = {
|
38
|
+
open:false,
|
39
|
+
star:'',
|
40
|
+
profile_image:'',
|
41
|
+
postOpen:false,
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
handleClose = () => {
|
46
|
+
this.setState({open: false,postOpen:false});
|
47
|
+
}
|
48
|
+
|
49
|
+
onCommentFncOpen = () => {
|
50
|
+
this.setState({open:true})
|
51
|
+
}
|
52
|
+
|
53
|
+
handleCommentSubmit = (val) =>{
|
54
|
+
this.writeNewComment(val)
|
55
|
+
}
|
56
|
+
|
57
|
+
handlePostOpen = () => {
|
58
|
+
this.setState({postOpen:true})
|
59
|
+
}
|
60
|
+
|
61
|
+
writeNewComment(val){
|
62
|
+
const self = this
|
63
|
+
var newCommentKey = firebase.database().ref().child('comments').push().key
|
64
|
+
|
65
|
+
firebase.database().ref('posts/' + self.props.post.postId + '/postComment').once("value").then(function(snapshot) {
|
66
|
+
const postCommentData = snapshot.val()
|
67
|
+
var commentData = {
|
68
|
+
author: self.props.author,
|
69
|
+
uid: self.props.myuid,
|
70
|
+
body: val,
|
71
|
+
commentId: newCommentKey,
|
72
|
+
profile_image:self.props.profile_image,
|
73
|
+
}
|
74
|
+
var updates = {}
|
75
|
+
updates['/comments/' + newCommentKey] = commentData
|
76
|
+
updates['posts/' + self.props.post.postId + '/postComment/commentCount/'] = postCommentData.commentCount+1
|
77
|
+
updates['posts/' + self.props.post.postId + '/postComment/comments/' + newCommentKey]= true
|
78
|
+
console.log(updates)
|
79
|
+
return firebase.database().ref().update(updates);
|
80
|
+
})
|
81
|
+
this.setState({open:false})
|
82
|
+
}
|
83
|
+
|
84
|
+
fetchPostsData(){
|
85
|
+
const self = this
|
86
|
+
const userId = this.props.post.uid
|
87
|
+
firebase.database().ref('/users/'+userId).once('value',function(snapshot) {
|
88
|
+
self.setState({
|
89
|
+
profile_image:snapshot.val().profile_image,
|
90
|
+
star:snapshot.val().userStar.starCount,
|
91
|
+
})
|
92
|
+
})
|
93
|
+
}
|
94
|
+
|
95
|
+
componentDidMount(){
|
96
|
+
this.fetchPostsData()
|
97
|
+
}
|
98
|
+
|
99
|
+
render(){
|
100
|
+
const actions = [
|
101
|
+
<FlatButton
|
102
|
+
label="Cancel"
|
103
|
+
primary={true}
|
104
|
+
onClick={this.handleClose} />,]
|
105
|
+
return(
|
106
|
+
<Card style={{
|
107
|
+
width:'300px',
|
108
|
+
display: 'inline-block',
|
109
|
+
marginRight:'10px',
|
110
|
+
verticalAlign: 'top',}} >
|
5
|
-
<CardHeader
|
111
|
+
<CardHeader
|
6
|
-
title={this.props.post.author}
|
7
|
-
|
112
|
+
title={
|
113
|
+
<div>
|
8
|
-
|
114
|
+
<Badge
|
9
|
-
|
115
|
+
badgeContent={this.state.star}
|
10
|
-
|
116
|
+
secondary={true}
|
11
|
-
|
117
|
+
badgeStyle={{top: 12, right: 12,fontSize:1}}
|
12
|
-
|
118
|
+
>
|
13
|
-
|
119
|
+
<Avatar src={this.state.profile_image} />
|
14
|
-
|
120
|
+
</Badge>
|
121
|
+
{this.props.post.author}
|
122
|
+
</div>
|
15
123
|
}
|
16
124
|
style={{
|
17
|
-
height:'
|
125
|
+
height:'70px',
|
18
126
|
cursor: 'pointer',
|
127
|
+
paddingTop:'0',
|
128
|
+
verticalAlign:'top'
|
19
129
|
}}
|
20
|
-
titleStyle={{
|
21
|
-
|
130
|
+
classes={{ title: this.props.classes.title }}
|
22
|
-
}}
|
23
131
|
onClick={() => this.props.herfUserPage(this.props.post.uid)} />
|
132
|
+
<CardTitle title={this.props.post.title}
|
133
|
+
subtitle={
|
134
|
+
<Timestamp time={this.props.post.timestamp/1000} format='full' includeDay/>
|
135
|
+
}
|
136
|
+
titleStyle={{
|
137
|
+
paddingTop:'0',
|
138
|
+
marginTop:'-20'
|
139
|
+
}}/>
|
140
|
+
<CardText style={{
|
141
|
+
paddingTop:'0',
|
142
|
+
}}
|
143
|
+
onClick={this.handlePostOpen}
|
144
|
+
>
|
145
|
+
<Linkify> {this.props.post.body} </Linkify>
|
146
|
+
<br />
|
147
|
+
<p style={{
|
148
|
+
textAlign:'center'
|
149
|
+
}}>
|
150
|
+
<img src={this.props.post.post_image}
|
151
|
+
alt=""
|
152
|
+
style={{
|
153
|
+
objectFit:'cover',
|
154
|
+
width:'270px',
|
155
|
+
hight:'270px',}}></img>
|
156
|
+
</p>
|
157
|
+
</CardText>
|
158
|
+
<CardActions style={{
|
159
|
+
paddingTop:'0',
|
160
|
+
}}>
|
161
|
+
<FlatButton
|
162
|
+
secondary
|
163
|
+
label="Comment"
|
164
|
+
onClick={this.onCommentFncOpen} />
|
165
|
+
</CardActions>
|
166
|
+
|
167
|
+
<CardHeader showExpandableButton
|
168
|
+
title={ <Badge badgeContent={this.props.post.postComment.commentCount}
|
169
|
+
primary={true}
|
170
|
+
badgeStyle={{fontSize:1,top: 12, right: 12}} >
|
171
|
+
<ChatIcon style={{size:'10px'}}/>
|
172
|
+
</Badge> }
|
173
|
+
style={{
|
174
|
+
paddingTop:'0',
|
175
|
+
marginTop:'-10',
|
176
|
+
marginBottom:'-25'
|
177
|
+
}}/>
|
178
|
+
<List expandable>
|
179
|
+
<CommentRef postId={this.props.post.postId} uid={this.props.post.uid}/>
|
180
|
+
</List>
|
181
|
+
|
182
|
+
<Dialog title="write comment"
|
183
|
+
actions={actions}
|
184
|
+
modal={false}
|
185
|
+
open={this.state.open}
|
186
|
+
onRequestClose={this.handleClose} >
|
187
|
+
<CommentForm onSubmit={this.handleCommentSubmit.bind(this)}/>
|
188
|
+
</Dialog>
|
189
|
+
|
190
|
+
<Dialog title={this.props.post.title}
|
191
|
+
actions={actions}
|
192
|
+
modal={false}
|
193
|
+
open={this.state.postOpen}
|
194
|
+
onRequestClose={this.handleClose} >
|
195
|
+
<div style={{
|
196
|
+
paddingTop:'0',
|
197
|
+
}} >
|
198
|
+
<Linkify> {this.props.post.body} </Linkify>
|
199
|
+
<br />
|
200
|
+
<p style={{
|
201
|
+
textAlign:'center'
|
202
|
+
}}>
|
203
|
+
<img src={this.props.post.post_image}
|
204
|
+
alt=""
|
205
|
+
style={{
|
206
|
+
objectFit:'cover',
|
207
|
+
width:'100%',
|
208
|
+
hight:'100%',}}></img>
|
209
|
+
</p>
|
210
|
+
</div>
|
211
|
+
</Dialog>
|
212
|
+
</Card>
|
213
|
+
)}
|
214
|
+
|
215
|
+
}
|
216
|
+
export default withStyles(myStyle)(PostRef)
|
217
|
+
|
24
218
|
```
|
25
219
|
|
26
220
|
これでは色を変えることができません。どこで間違えてますでしょうか?
|
2
変更
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
1
変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
CSS
|
1
|
+
CSS hoverColorの指定について。
|
body
CHANGED
File without changes
|