morethanwords
4 years ago
8 changed files with 161 additions and 47 deletions
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
import { BotCommand } from "../../layer"; |
||||
import RichTextProcessor from "../../lib/richtextprocessor"; |
||||
import AvatarElement from "../avatar"; |
||||
import Scrollable from "../scrollable"; |
||||
import AutocompleteHelper from "./autocompleteHelper"; |
||||
|
||||
export default class CommandsHelper extends AutocompleteHelper { |
||||
private scrollable: Scrollable; |
||||
|
||||
constructor(appendTo: HTMLElement) { |
||||
super(appendTo, 'y', (target) => { |
||||
|
||||
}); |
||||
|
||||
this.container.classList.add('commands-helper'); |
||||
} |
||||
|
||||
private init() { |
||||
this.list = document.createElement('div'); |
||||
this.list.classList.add('commands-helper-commands'); |
||||
|
||||
this.container.append(this.list); |
||||
|
||||
this.scrollable = new Scrollable(this.container); |
||||
|
||||
this.addEventListener('visible', () => { |
||||
setTimeout(() => { // it is not rendered yet
|
||||
this.scrollable.container.scrollTop = 0; |
||||
}, 0); |
||||
}); |
||||
} |
||||
|
||||
public renderCommands(commands: {userId: number, command: BotCommand}[]) { |
||||
if(this.init) { |
||||
if(!commands.length) { |
||||
return; |
||||
} |
||||
|
||||
this.init(); |
||||
this.init = null; |
||||
} |
||||
|
||||
if(commands.length) { |
||||
this.list.innerHTML = ''; |
||||
commands.forEach(command => { |
||||
const div = document.createElement('div'); |
||||
div.classList.add('commands-helper-command'); |
||||
|
||||
const avatar = new AvatarElement(); |
||||
avatar.classList.add('avatar-30'); |
||||
avatar.setAttribute('dialog', '0'); |
||||
avatar.setAttribute('peer', '' + command.userId); |
||||
|
||||
const name = document.createElement('div'); |
||||
name.classList.add('commands-helper-command-name'); |
||||
name.innerText = '/' + command.command.command; |
||||
|
||||
const description = document.createElement('div'); |
||||
description.classList.add('commands-helper-command-description'); |
||||
description.innerHTML = RichTextProcessor.wrapEmojiText(command.command.description); |
||||
|
||||
div.append(avatar, name, description); |
||||
this.list.append(div); |
||||
}); |
||||
} |
||||
|
||||
this.toggle(!commands.length); |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
.commands-helper { |
||||
left: 0; |
||||
//width: 320px !important; |
||||
|
||||
.scrollable { |
||||
position: relative; |
||||
max-height: 232px; |
||||
} |
||||
|
||||
&-commands { |
||||
padding: .5rem 0; |
||||
} |
||||
|
||||
&-command { |
||||
height: 3.125rem; |
||||
display: flex; |
||||
padding: 0 .75rem; |
||||
align-items: center; |
||||
cursor: pointer; |
||||
|
||||
@include hover(); |
||||
|
||||
&-name { |
||||
margin-left: .875rem; |
||||
font-weight: 500; |
||||
} |
||||
|
||||
&-description { |
||||
margin-left: .5625rem; |
||||
color: var(--secondary-text-color); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue