Skip to content

Commit

Permalink
perf: fix some performance issues in macro prompt dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou committed Oct 29, 2023
1 parent b560dff commit 9b9c800
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/components/dialogs/TheMacroPrompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,22 @@ export default class TheMacroPrompt extends Mixins(BaseMixin) {
return this.$store.state.server.events
}
get actions() {
return this.events.filter(
(event: ServerStateEvent) => event.type === 'action' && event.message.startsWith('// action:prompt_')
)
}
get macroPromptEvents() {
return this.actions.map((event: ServerStateEvent) => {
const type = (event.message ?? '').replace('// action:prompt_', '').split(' ')[0].trim()
const message = (event.message ?? '').replace(`// action:prompt_${type}`, '').replace(/"/g, '').trim()
const promptContent: ServerStateEventPrompt = {
date: event.date,
type,
message,
}
return promptContent
})
return this.events
.filter((event: ServerStateEvent) => event.type === 'action')
.filter((event: ServerStateEvent) => event.message.startsWith('// action:prompt_'))
.map((event: ServerStateEvent) => {
const type = (event.message ?? '').replace('// action:prompt_', '').split(' ')[0].trim()
const message = (event.message ?? '').replace(`// action:prompt_${type}`, '').replace(/"/g, '').trim()
const promptContent: ServerStateEventPrompt = {
date: event.date,
type,
message,
}
return promptContent
})
}
get lastPromptBeginPos() {
Expand All @@ -101,7 +98,7 @@ export default class TheMacroPrompt extends Mixins(BaseMixin) {
get showDialog() {
if (this.lastPromptBeginPos === -1) return false
return this.lastPromptBeginPos > this.lastPromptClosePos
return this.lastPromptBeginPos > this.lastPromptClosePos && this.activePromptContent.length > 0
}
get activePrompt() {
Expand Down

0 comments on commit 9b9c800

Please sign in to comment.