-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeed.js
91 lines (71 loc) · 2.88 KB
/
Feed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React, { useEffect, useState } from "react";
import './Feed.css';
import CreateIcon from "@material-ui/icons/Create";
import ImageIcon from "@material-ui/icons/Image";
import InputOption from './InputOption';
import SubscriptionsIcon from "@material-ui/icons/Subscriptions";
import EventNoteIcon from "@material-ui/icons/EventNote";
import CalendarViewDayIcon from "@material-ui/icons/CalendarViewDay";
import Post from './Post';
import { db } from "./firebase";
import firebase from './firebase';
import { useSelector } from "react-redux";
import { selectUser } from "./features/userSlice";
import FlipMove from 'react-flip-move';
function Feed() {
const user = useSelector(selectUser);
const [input, setInput] = useState("");
const [posts, setPosts] = useState([]);
useEffect(() => {
db.collection("posts").orderBy('timestamp', 'desc').onSnapshot(snapshot => (
setPosts(snapshot.docs.map(doc => (
{
id: doc.id,
data: doc.data(),
}
)))
))
}, [])
const sendPost = e => {
e.preventDefault();
db.collection('posts').add({
name: user.displayName,
description: user.email,
message: input,
photoUrl: user.photoUrl || "",
timestamp: firebase.firestore.FieldValue.serverTimestamp(),
});
setInput("");
};
return (
<div className="feed">
<div className="feed__inputContainer">
<div className="feed__input">
<CreateIcon />
<form>
<input value={input} onChange={e => setInput(e.target.value)} type="text" />
<button onClick={sendPost} type="submit">Send</button>
</form>
</div>
<div className="feed__inputOptions">
<InputOption Icon={ImageIcon} title="Photo" color="#70b5f9" />
<InputOption Icon={SubscriptionsIcon} title="Video" color="#7E7A33E" />
<InputOption Icon={EventNoteIcon} title="Event" color="#C0CBCD" />
<InputOption Icon={CalendarViewDayIcon} title="Write article" color="#7FC15E" />
</div>
</div>
<FlipMove>
{posts.map(({ id, data: { name, description, message, photoUrl }}) => (
<Post
key={id}
name={name}
description={description}
message={message}
photoUrl={photoUrl}
/>
))}
</FlipMove>
</div>
);
};
export default Feed;