fchat-rising/chat/StatusSwitcher.vue

118 lines
4.3 KiB
Vue
Raw Permalink Normal View History

2017-09-02 01:50:31 +00:00
<template>
2023-05-28 03:00:51 +00:00
<modal :action="l('chat.setStatus')" @submit="setStatus" @close="reset" dialogClass="w-100 modal-lg statusEditor">
2017-09-02 01:50:31 +00:00
<div class="form-group" id="statusSelector">
<label class="control-label">{{l('chat.setStatus.status')}}</label>
2019-09-17 17:14:14 +00:00
<dropdown linkClass="custom-select">
<span slot="title"><span class="fa fa-fw" :class="getStatusIcon(status)"></span>{{l('status.' + status)}}</span>
<a href="#" class="dropdown-item" v-for="item in statuses" @click.prevent="status = item">
<span class="fa fa-fw" :class="getStatusIcon(item)"></span>{{l('status.' + item)}}
</a>
</dropdown>
2017-09-02 01:50:31 +00:00
</div>
<div class="form-group">
<label class="control-label">{{l('chat.setStatus.message')}}</label>
2018-07-20 01:12:26 +00:00
<editor id="text" v-model="text" classes="form-control" maxlength="255">
<div class="bbcode-editor-controls">
2017-09-02 01:50:31 +00:00
{{getByteLength(text)}} / 255
</div>
</editor>
</div>
2020-03-21 18:35:22 +00:00
<div class="form-group">
<button type="button" @click="showStatusPicker" class="btn btn-outline-secondary">History</button>
</div>
<status-picker ref="statusPicker" :callback="insertStatusMessage" :curStatus="enteredText"></status-picker>
2017-09-02 01:50:31 +00:00
</modal>
</template>
<script lang="ts">
2019-01-03 17:38:17 +00:00
import {Component} from '@f-list/vue-ts';
2017-09-02 01:50:31 +00:00
import CustomDialog from '../components/custom_dialog';
import Dropdown from '../components/Dropdown.vue';
2017-09-02 01:50:31 +00:00
import Modal from '../components/Modal.vue';
import {Editor} from './bbcode';
import {getByteLength} from './common';
import core from './core';
import {Character, userStatuses} from './interfaces';
import l from './localize';
2019-07-15 16:59:16 +00:00
import {getStatusIcon} from './UserView.vue';
2020-03-21 18:35:22 +00:00
import StatusPicker from './StatusPicker.vue';
import * as _ from 'lodash';
2017-09-02 01:50:31 +00:00
@Component({
2020-03-21 18:35:22 +00:00
components: {modal: Modal, editor: Editor, dropdown: Dropdown, 'status-picker': StatusPicker}
2017-09-02 01:50:31 +00:00
})
export default class StatusSwitcher extends CustomDialog {
2019-01-03 17:38:17 +00:00
selectedStatus: Character.Status | undefined;
enteredText: string | undefined;
2017-09-02 01:50:31 +00:00
statuses = userStatuses;
l = l;
getByteLength = getByteLength;
getStatusIcon = getStatusIcon;
get status(): Character.Status {
2019-01-03 17:38:17 +00:00
return this.selectedStatus !== undefined ? this.selectedStatus : this.character.status;
2017-09-02 01:50:31 +00:00
}
set status(status: Character.Status) {
this.selectedStatus = status;
}
get text(): string {
2019-01-03 17:38:17 +00:00
return this.enteredText !== undefined ? this.enteredText : this.character.statusText;
2017-09-02 01:50:31 +00:00
}
set text(text: string) {
this.enteredText = text;
}
get character(): Character {
return core.characters.ownCharacter;
}
setStatus(): void {
core.connection.send('STA', {status: this.status, statusmsg: this.text});
2020-03-21 18:35:22 +00:00
// tslint:disable-next-line
this.updateHistory(this.text);
2017-09-02 01:50:31 +00:00
}
reset(): void {
2019-01-03 17:38:17 +00:00
this.selectedStatus = undefined;
this.enteredText = undefined;
2017-09-02 01:50:31 +00:00
}
2020-03-21 18:35:22 +00:00
insertStatusMessage(statusMessage: string): void {
this.text = statusMessage;
}
async updateHistory(statusMessage: string): Promise<void> {
if ((!statusMessage) || (statusMessage.trim() === '')) {
return;
}
const curHistory: string[] = (await core.settingsStore.get('statusHistory')) || [];
const statusMessageClean = statusMessage.toString().trim().toLowerCase();
const filteredHistory: string[] = _.reject(curHistory, (c: string) => (c.toString().trim().toLowerCase() === statusMessageClean));
const newHistory: string[] = _.take(_.concat([statusMessage], filteredHistory), 10);
await core.settingsStore.set('statusHistory', newHistory);
}
showStatusPicker(): void {
(<StatusPicker>this.$refs['statusPicker']).show();
}
2017-09-02 01:50:31 +00:00
}
2020-03-21 18:35:22 +00:00
</script>
2023-05-28 03:00:51 +00:00
<style lang="scss">
.statusEditor .bbcode-toolbar .color-selector {
left: 58px !important;
}
2023-05-29 04:13:16 +00:00
.statusEditor .bbcode-toolbar .eicon-selector {
top: 30px !important;
}
2023-05-28 03:00:51 +00:00
</style>