Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
160 additions
and
106 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { h } from 'snabbdom' | ||
import { VNode } from 'snabbdom/vnode' | ||
import { Convo } from '../interfaces' | ||
import { bind } from './util'; | ||
import MsgCtrl from '../ctrl'; | ||
|
||
export default function renderActions(ctrl: MsgCtrl, convo: Convo): VNode[] { | ||
const user = convo.thread.contact, nodes = []; | ||
const cls = 'msg-app__convo__action.button.button-empty'; | ||
nodes.push( | ||
h(`a.${cls}`, { | ||
key: 'play', | ||
attrs: { | ||
'data-icon': 'U', | ||
href: `/?user=${user.name}#friend`, | ||
title: ctrl.trans.noarg('challengeToPlay') | ||
} | ||
}) | ||
); | ||
if (convo.relations.out === false) nodes.push( | ||
h(`button.${cls}.unbad.text.hover-text`, { | ||
key: 'unblock', | ||
attrs: { | ||
'data-icon': 'k', | ||
title: ctrl.trans.noarg('blocked'), | ||
'data-hover-text': ctrl.trans.noarg('unblock') | ||
}, | ||
hook: bind('click', ctrl.unblock) | ||
}) | ||
); | ||
else nodes.push( | ||
h(`button.${cls}.bad`, { | ||
key: 'block', | ||
attrs: { | ||
'data-icon': 'k', | ||
title: ctrl.trans.noarg('block') | ||
}, | ||
hook: bind('click', ctrl.block) | ||
}) | ||
); | ||
nodes.push( | ||
h(`button.${cls}.bad.confirm`, { | ||
key: 'report', | ||
attrs: { | ||
'data-icon': '!', | ||
href: '/report/flag', | ||
title: ctrl.trans.noarg('report') | ||
} | ||
}) | ||
); | ||
return nodes; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { h } from 'snabbdom' | ||
import { VNode } from 'snabbdom/vnode' | ||
import { User } from '../interfaces' | ||
import MsgCtrl from '../ctrl'; | ||
import throttle from 'common/throttle'; | ||
|
||
export default function renderTextarea(ctrl: MsgCtrl, user: User): VNode { | ||
return h('textarea.msg-app__convo__reply__text', { | ||
attrs: { | ||
rows: 1, | ||
autofocus: 1 | ||
}, | ||
hook: { | ||
insert(vnode) { | ||
setupTextarea(vnode.elm as HTMLTextAreaElement, user.id, ctrl.post); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function setupTextarea(area: HTMLTextAreaElement, contact: string, post: (text: string) => void) { | ||
|
||
// save the textarea content until sent | ||
const storage = window.lichess.storage.make(`msg:area:${contact}`); | ||
|
||
// hack to automatically resize the textarea based on content | ||
area.value = ''; | ||
let baseScrollHeight = area.scrollHeight; | ||
area.addEventListener('input', throttle(500, () => | ||
setTimeout(() => { | ||
const text = area.value.trim(); | ||
area.rows = 1; | ||
// the resize magic | ||
if (text) area.rows = Math.min(10, 1 + Math.ceil((area.scrollHeight - baseScrollHeight) / 19)); | ||
// and save content | ||
storage.set(text); | ||
}) | ||
)); | ||
|
||
// restore previously saved content | ||
area.value = storage.get() || ''; | ||
if (area.value) area.dispatchEvent(new Event('input')); | ||
|
||
// send the content on <enter. | ||
area.addEventListener('keypress', (e: KeyboardEvent) => { | ||
if ((e.which == 10 || e.which == 13) && !e.shiftKey) { | ||
setTimeout(() => { | ||
const txt = area.value.trim(); | ||
if (txt) post(txt); | ||
area.value = ''; | ||
area.dispatchEvent(new Event('input')); // resize the textarea | ||
storage.remove(); | ||
}); | ||
} | ||
}); | ||
area.focus(); | ||
} |