-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite.jsx
137 lines (129 loc) · 3.6 KB
/
website.jsx
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
require("css-baseline/css/super-1.css")
require("roboto-fontface/css/roboto/roboto-fontface.css")
let quik = require("quik-client")
let DropdownInput = require("./code/dropdownInput")
let Song = require("./code/song")
let getPlaylists = quik.backend.getPlaylists
let { blue, green } = require("./code/colors")
// FIXME
// when connection is lost, typing is allowed but if the server doesn't respond no error message is given
let dropdownWrapper = (
<DropdownInput
input={{
placeholder: "Start typing a sentence",
autofocus: true,
oninput: onInput,
style: {
border: "none",
borderBottom: "solid gray 2px",
fontSize: "1.2rem",
paddingTop: "0.4rem",
width: '14rem',
maxWidth: '90vw',
},
}}
dropdown={{
style: {
padding: "0.2rem",
color: "gray",
height: "5.3em",
overflow: "auto",
},
}}
/>
)
let marginTop = "1rem"
let confirmedSongsContainer = (
<div
style={{
backgroundColor: green,
width: "100%",
overflowY: 'auto',
minHeight: `calc(50vh - ${marginTop})`,
maxHeight: `calc(50vh - ${marginTop})`,
color: "white",
justifyContent: "flex-start",
marginTop: marginTop,
paddingTop: "1.6rem",
flexDirection: "column",
}}
>
No songs yet ¯\_(ツ)_/¯
</div>
)
let messageContainer = (
<div
style={{
height: "10vh",
alignItems: "flex-end",
fontWeight: "bold",
}}
>
<span>Hello</span>
</div>
)
// set the root font size
document.querySelector(":root").style.fontSize = "20px"
document.head = (
<head>
<title>Phrasify</title>
</head>
)
document.body = (
<body>
<div style={{
flexDirection: 'column',
minHeight: "50vh",
maxHeight: "50vh"
}}>
<div style="height: 15vh;" />
<h2 style={{ minHeight: "1em", fontFamily: "Roboto", fontWeight: 100 }}>Phrasify</h2>
{messageContainer}
{dropdownWrapper}
</div>
{confirmedSongsContainer}
</body>
)
//
// setup the dropdown
//
let confirmedSongs = []
async function onInput(e) {
let currentText = e.target.value
try {
console.log(`currentText is:`, currentText)
var results = await getPlaylists(currentText, confirmedSongs)
} catch (e) {
console.error(`There was an error on the backend`, e.message)
}
confirmedSongs = results.confirmedSongs
let { startMatches, messages } = results
//
// Change UI of Confirmed songs
//
// remove all the old songs
confirmedSongsContainer.children = []
// add the new songs
for (let each of confirmedSongs) {
console.log('adding confirmed song')
confirmedSongsContainer.add(<Song {...each} />)
}
if (confirmedSongsContainer.children.length == 0) {
confirmedSongsContainer.add("No songs yet ¯\\_(ツ)_/¯ ")
}
//
// Change the UI of the Suggested songs
//
dropdownWrapper.dropdown.children = []
// add the new suggestions
for (let each of startMatches) {
dropdownWrapper.dropdown.add(<span>{`${each.title}`}</span>)
}
//
// Change the UI of messages if there are any
//
messageContainer.children = []
for (let each of messages) {
messageContainer.add(<span>{each}</span>)
}
}