Skip to content

Commit c47c9f5

Browse files
feat: add loading state
1 parent 8dcc3e3 commit c47c9f5

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

src/App.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,58 @@ sub {
341341
font-size: 12px;
342342
}
343343

344+
.lds-ellipsis {
345+
display: inline-block;
346+
position: relative;
347+
width: 80px;
348+
height: 80px;
349+
}
350+
.lds-ellipsis div {
351+
position: absolute;
352+
top: 33px;
353+
width: 13px;
354+
height: 13px;
355+
border-radius: 50%;
356+
background: #fff;
357+
animation-timing-function: cubic-bezier(0, 1, 1, 0);
358+
}
359+
.lds-ellipsis div:nth-child(1) {
360+
left: 8px;
361+
animation: lds-ellipsis1 0.6s infinite;
362+
}
363+
.lds-ellipsis div:nth-child(2) {
364+
left: 8px;
365+
animation: lds-ellipsis2 0.6s infinite;
366+
}
367+
.lds-ellipsis div:nth-child(3) {
368+
left: 32px;
369+
animation: lds-ellipsis2 0.6s infinite;
370+
}
371+
.lds-ellipsis div:nth-child(4) {
372+
left: 56px;
373+
animation: lds-ellipsis3 0.6s infinite;
374+
}
375+
@keyframes lds-ellipsis1 {
376+
0% {
377+
transform: scale(0);
378+
}
379+
100% {
380+
transform: scale(1);
381+
}
382+
}
383+
@keyframes lds-ellipsis3 {
384+
0% {
385+
transform: scale(1);
386+
}
387+
100% {
388+
transform: scale(0);
389+
}
390+
}
391+
@keyframes lds-ellipsis2 {
392+
0% {
393+
transform: translate(0, 0);
394+
}
395+
100% {
396+
transform: translate(24px, 0);
397+
}
398+
}

src/WriteOMeterForm.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ class WriteOMeterForm extends React.Component {
3333
value: 'Γράψτε εδώ το κείμενο προς ανάλυση.',
3434
method: 'spacy-lib',
3535
results: null,
36+
isLoading: false
3637
}
3738
this.handleChange = this.handleChange.bind(this)
3839
this.handleAnalysisMethodChange = this.handleAnalysisMethodChange.bind(this)
3940
this.handleSubmit = this.handleSubmit.bind(this)
4041
this.getClassByPartOfSpeech = this.getClassByPartOfSpeech.bind(this)
4142
this.showResults = this.showResults.bind(this)
43+
this.showLoadingState = this.showLoadingState.bind(this)
4244
}
4345

4446
handleChange(event) {
@@ -85,10 +87,22 @@ class WriteOMeterForm extends React.Component {
8587
}
8688
}
8789

90+
showLoadingState() {
91+
return (
92+
<div class="lds-ellipsis">
93+
<div></div>
94+
<div></div>
95+
<div></div>
96+
<div></div>
97+
</div>
98+
)
99+
}
100+
88101
async handleSubmit(event) {
89102
event.preventDefault()
90103
try {
91104
let response
105+
this.setState({isLoading: true})
92106
if (this.state.method === 'spacy-lib') {
93107
response = await analyzeWithSpacy(this.state.value)
94108
} else {
@@ -98,11 +112,14 @@ class WriteOMeterForm extends React.Component {
98112
this.setState({ results })
99113
} catch (e) {
100114
console.error(e)
115+
} finally {
116+
this.setState({ isLoading: false })
101117
}
102118
}
103119

104120
render() {
105121
const hasResults = !!this.state.results
122+
const isLoading = this.state.isLoading
106123
return (
107124
<form className="wom-form" onSubmit={this.handleSubmit}>
108125
<section className="wom-form__controls">
@@ -140,7 +157,8 @@ class WriteOMeterForm extends React.Component {
140157
{hasResults && this.showStatisticResults()}
141158
</section>
142159
</section>
143-
<input className="wom-form__input" type="submit" value="Aνάλυση" />
160+
<input disabled={this.state.isLoading} className="wom-form__input" type="submit" value="Aνάλυση" />
161+
{isLoading && this.showLoadingState()}
144162
{hasResults && this.showResults()}
145163
</form>
146164
)

0 commit comments

Comments
 (0)