fchat-rising/chat/user_view.ts

57 lines
2.6 KiB
TypeScript
Raw Normal View History

2017-09-02 01:50:31 +00:00
// TODO convert this to single-file once Vue supports it for functional components.
//template:
//<span class="gender" :class="genderClass" @click="click" @contextmenu.prevent="showMenu" style="cursor:pointer;" ref="main"><span
//class="fa" :class="statusIcon"></span> <span class="fa" :class="rankIcon"></span>{{character.name}}</span>
import Vue, {CreateElement, RenderContext, VNode} from 'vue';
2018-03-28 13:51:05 +00:00
import {Channel, Character} from '../fchat';
import core from './core';
2017-09-02 01:50:31 +00:00
export function getStatusIcon(status: Character.Status): string {
switch(status) {
case 'online':
return 'far fa-user';
2017-09-02 01:50:31 +00:00
case 'looking':
return 'fa fa-eye';
2017-09-02 01:50:31 +00:00
case 'dnd':
return 'fa fa-minus-circle';
2017-09-02 01:50:31 +00:00
case 'offline':
return 'fa fa-ban';
2017-09-02 01:50:31 +00:00
case 'away':
return 'far fa-circle';
2017-09-02 01:50:31 +00:00
case 'busy':
return 'fa fa-cog';
2017-09-02 01:50:31 +00:00
case 'idle':
return 'far fa-clock';
2017-09-02 01:50:31 +00:00
case 'crown':
return 'fa fa-birthday-cake';
2017-09-02 01:50:31 +00:00
}
}
//tslint:disable-next-line:variable-name
const UserView = Vue.extend({
functional: true,
render(this: void | Vue, createElement: CreateElement, context?: RenderContext): VNode {
2017-09-02 01:50:31 +00:00
const props = <{character: Character, channel?: Channel, showStatus?: true}>(
context !== undefined ? context.props : (<Vue>this).$options.propsData);
2017-09-02 01:50:31 +00:00
const character = props.character;
let rankIcon;
if(character.isChatOp) rankIcon = 'far fa-gem';
else if(props.channel !== undefined)
rankIcon = props.channel.owner === character.name ? 'fa fa-key' : props.channel.opList.indexOf(character.name) !== -1 ?
(props.channel.id.substr(0, 4) === 'adh-' ? 'fa fa-shield-alt' : 'fa fa-star') : '';
else rankIcon = '';
2018-03-28 13:51:05 +00:00
const children: (VNode | string)[] = [character.name];
if(rankIcon !== '') children.unshift(createElement('span', {staticClass: rankIcon}));
if(props.showStatus !== undefined || character.status === 'crown')
children.unshift(createElement('span', {staticClass: `fa-fw ${getStatusIcon(character.status)}`}));
const gender = character.gender !== undefined ? character.gender.toLowerCase() : 'none';
const isBookmark = core.connection.isOpen && core.state.settings.colorBookmarks && (character.isFriend || character.isBookmarked);
2017-09-02 01:50:31 +00:00
return createElement('span', {
attrs: {class: `user-view gender-${gender}${isBookmark ? ' user-bookmark' : ''}`},
2018-03-28 13:51:05 +00:00
domProps: {character, channel: props.channel, bbcodeTag: 'user'}
}, children);
2017-09-02 01:50:31 +00:00
}
});
export default UserView;