forked from DataStax-Examples/astra-tik-tok
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathUpload.js
78 lines (71 loc) · 2.09 KB
/
Upload.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
import React, { useState } from 'react'
import axios from 'axios'
import faker from "faker"
const Upload = () => {
const username = 'aniak100'
const name = 'Ania Kubow'
const avatar = 'https://i.imgur.com/QwZod6m.png'
const [video, setVideo] = useState(null)
const [caption, setCaption] = useState(null)
const today = new Date()
const timestamp = today.toISOString()
let id = faker.random.uuid()
const handleSubmit = async (e) => {
e.preventDefault()
const data = {
id: id,
name: name,
username: username,
avatar: avatar,
is_followed: false,
video: video,
caption: caption,
likes: 0,
comments: 0,
timestamp: timestamp,
button_visible: false
}
axios.post('/.netlify/functions/add', data)
.then((response) => {
console.log(response)
})
.catch((err) => {
console.error(err)
})
}
return (
<div className="upload-page">
<br />
<h1>Upload video</h1>
<p>This video will be published to @{username}</p>
<div className='container'>
<form onSubmit={handleSubmit}>
<div className='section'>
<div className="image-upload"></div>
<div className="form-section">
<div className='section input-section'>
<label className="bold">Caption</label>
<input
className='input'
name='caption'
onChange={(e) => setCaption(e.target.value)}
/>
</div>
<div className="break"></div>
<div className='section input-section'>
<label className="bold">Video Url</label>
<input
className='input'
name='video'
onChange={(e) => setVideo(e.target.value)}
/>
</div>
</div>
</div>
<button>Post</button>
</form>
</div>
</div>
)
}
export default Upload