remember favourite chat tab

This commit is contained in:
Thibault Duplessis 2017-08-17 19:00:34 -05:00
parent 998756be28
commit ce62c49ceb
4 changed files with 14 additions and 7 deletions

View file

@ -16,7 +16,7 @@ userId: @jsUserId,
tour: @jsOrNull(tour.flatMap(_.top).map(lila.tournament.JsonView.top(_, lightUser))),
chat: @jsOrNull(chatOption.map(_.either).map {
case Left(c) => {
chat.ChatJsData.restricted(c, name = trans.chatRoom.txt(), timeout = false, withNote = true, public = false)
chat.ChatJsData.restricted(c, name = trans.chatRoom.txt(), timeout = false, withNote = ctx.isAuth, public = false)
}
case Right(c) => {
chat.ChatJsData.json(c.chat, name = trans.chatRoom.txt(), timeout = c.timeout, public = true)

View file

@ -11,10 +11,17 @@ export default function(opts: ChatOpts, redraw: Redraw): Ctrl {
const pubsub = li.pubsub;
const allTabs: Tab[] = ['discussion'];
if (opts.noteId) allTabs.push('note');
if (opts.plugin) allTabs.push(opts.plugin.tab.key);
const tabStorage = li.storage.make('chat.tab'),
storedTab = tabStorage.get();
let moderation: ModerationCtrl | undefined;
const vm: ViewModel = {
tab: 'discussion',
tab: allTabs.indexOf(storedTab) > -1 ? storedTab : allTabs[0],
enabled: opts.alwaysEnabled || !li.storage.get('nochat'),
placeholderKey: 'talkInChat',
loading: false,
@ -71,7 +78,7 @@ export default function(opts: ChatOpts, redraw: Redraw): Ctrl {
}
instanciateModeration();
const note = data.userId && opts.noteId ? noteCtrl({
const note = opts.noteId ? noteCtrl({
id: opts.noteId,
trans,
redraw
@ -104,8 +111,10 @@ export default function(opts: ChatOpts, redraw: Redraw): Ctrl {
data,
opts,
vm,
allTabs,
setTab(t: Tab) {
vm.tab = t;
tabStorage.set(t);
redraw()
},
moderation: () => moderation,

View file

@ -55,6 +55,7 @@ export interface Ctrl {
data: ChatData
opts: ChatOpts
vm: ViewModel
allTabs: Tab[]
preset: PresetCtrl
note?: NoteCtrl
moderation(): ModerationCtrl | undefined

View file

@ -19,11 +19,8 @@ export default function(ctrl: Ctrl): VNode {
function normalView(ctrl: Ctrl) {
const active = ctrl.vm.tab;
const tabs: Array<Tab> = ['discussion'];
if (ctrl.note) tabs.push('note');
if (ctrl.plugin) tabs.push(ctrl.plugin.tab.key);
return [
h('div.chat_tabs.nb_' + tabs.length, tabs.map(t => renderTab(ctrl, t, active))),
h('div.chat_tabs.nb_' + ctrl.allTabs.length, ctrl.allTabs.map(t => renderTab(ctrl, t, active))),
h('div.content.' + active,
(active === 'note' && ctrl.note) ? [noteView(ctrl.note)] : (
ctrl.plugin && active === ctrl.plugin.tab.key ? [ctrl.plugin.view()] : discussionView(ctrl)