Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UX: Refactor AI summarizing animation (#22839)
- Loading branch information
1 parent
331507f
commit 0f1479e
Showing
4 changed files
with
277 additions
and
61 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
app/assets/javascripts/discourse/app/components/ai-summary-skeleton.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<ul class="ai-summary__list" {{did-insert this.setupAnimation}}> | ||
{{#each this.blocks as |block|}} | ||
<li | ||
class={{concat-class | ||
"ai-summary__list-item" | ||
(if block.show "show") | ||
(if block.shown "is-shown") | ||
(if block.blinking "blink") | ||
}} | ||
{{did-update (fn this.onBlinking block) block.blinking}} | ||
{{did-update (fn this.onShowing block) block.show}} | ||
{{will-destroy this.teardownAnimation}} | ||
></li> | ||
{{/each}} | ||
</ul> | ||
|
||
<span> | ||
<div class="ai-summary__generating-text"> | ||
{{i18n "summary.in_progress"}} | ||
</div> | ||
<span class="ai-summary__indicator-wave"> | ||
<span class="ai-summary__indicator-dot">.</span> | ||
<span class="ai-summary__indicator-dot">.</span> | ||
<span class="ai-summary__indicator-dot">.</span> | ||
</span> | ||
</span> |
92 changes: 92 additions & 0 deletions
92
app/assets/javascripts/discourse/app/components/ai-summary-skeleton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import Component from "@glimmer/component"; | ||
import { action } from "@ember/object"; | ||
import { tracked } from "@glimmer/tracking"; | ||
import discourseLater from "discourse-common/lib/later"; | ||
import { cancel } from "@ember/runloop"; | ||
|
||
class Block { | ||
@tracked show = false; | ||
@tracked shown = false; | ||
@tracked blinking = false; | ||
|
||
constructor(args = {}) { | ||
this.show = args.show ?? false; | ||
this.shown = args.shown ?? false; | ||
} | ||
} | ||
|
||
const BLOCKS_SIZE = 20; // changing this requires to change css accordingly | ||
|
||
export default class AiSummarySkeleton extends Component { | ||
blocks = [...Array.from({ length: BLOCKS_SIZE }, () => new Block())]; | ||
|
||
#nextBlockBlinkingTimer; | ||
#blockBlinkingTimer; | ||
#blockShownTimer; | ||
|
||
@action | ||
setupAnimation() { | ||
this.blocks.firstObject.show = true; | ||
this.blocks.firstObject.shown = true; | ||
} | ||
|
||
@action | ||
onBlinking(block) { | ||
if (!block.blinking) { | ||
return; | ||
} | ||
|
||
block.show = false; | ||
|
||
this.#nextBlockBlinkingTimer = discourseLater( | ||
this, | ||
() => { | ||
this.#nextBlock(block).blinking = true; | ||
}, | ||
250 | ||
); | ||
|
||
this.#blockBlinkingTimer = discourseLater( | ||
this, | ||
() => { | ||
block.blinking = false; | ||
}, | ||
500 | ||
); | ||
} | ||
|
||
@action | ||
onShowing(block) { | ||
if (!block.show) { | ||
return; | ||
} | ||
|
||
this.#blockShownTimer = discourseLater( | ||
this, | ||
() => { | ||
this.#nextBlock(block).show = true; | ||
this.#nextBlock(block).shown = true; | ||
|
||
if (this.blocks.lastObject === block) { | ||
this.blocks.firstObject.blinking = true; | ||
} | ||
}, | ||
250 | ||
); | ||
} | ||
|
||
@action | ||
teardownAnimation() { | ||
cancel(this.#blockShownTimer); | ||
cancel(this.#nextBlockBlinkingTimer); | ||
cancel(this.#blockBlinkingTimer); | ||
} | ||
|
||
#nextBlock(currentBlock) { | ||
if (currentBlock === this.blocks.lastObject) { | ||
return this.blocks.firstObject; | ||
} else { | ||
return this.blocks.objectAt(this.blocks.indexOf(currentBlock) + 1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters