misskey/src/client/ui/chat/index.vue

467 lines
12 KiB
Vue
Raw Normal View History

<template>
<div class="mk-app" @contextmenu.self.prevent="onContextmenu">
<XSidebar ref="menu" class="menu" :default-hidden="true"/>
<div class="nav">
<header class="header">
<div class="left">
<button class="_button account" @click="openAccountMenu">
2021-02-16 10:21:44 +01:00
<MkAvatar :user="$i" class="avatar"/><!--<MkAcct class="text" :user="$i"/>-->
</button>
</div>
<div class="right">
<MkA class="item" to="/my/messaging" v-tooltip="$ts.messaging"><i class="fas fa-comments icon"></i><span v-if="$i.hasUnreadMessagingMessage" class="indicator"><i class="fas fa-circle"></i></span></MkA>
<MkA class="item" to="/my/messages" v-tooltip="$ts.directNotes"><i class="fas fa-envelope icon"></i><span v-if="$i.hasUnreadSpecifiedNotes" class="indicator"><i class="fas fa-circle"></i></span></MkA>
<MkA class="item" to="/my/mentions" v-tooltip="$ts.mentions"><i class="fas fa-at icon"></i><span v-if="$i.hasUnreadMentions" class="indicator"><i class="fas fa-circle"></i></span></MkA>
<MkA class="item" to="/my/notifications" v-tooltip="$ts.notifications"><i class="fas fa-bell icon"></i><span v-if="$i.hasUnreadNotification" class="indicator"><i class="fas fa-circle"></i></span></MkA>
</div>
</header>
<div class="body">
<div class="container">
<div class="header">{{ $ts.timeline }}</div>
<div class="body">
<MkA to="/timeline/home" class="item" :class="{ active: tl === 'home' }"><i class="fas fa-home icon"></i>{{ $ts._timelines.home }}</MkA>
<MkA to="/timeline/local" class="item" :class="{ active: tl === 'local' }"><i class="fas fa-comments icon"></i>{{ $ts._timelines.local }}</MkA>
<MkA to="/timeline/social" class="item" :class="{ active: tl === 'social' }"><i class="fas fa-share-alt icon"></i>{{ $ts._timelines.social }}</MkA>
<MkA to="/timeline/global" class="item" :class="{ active: tl === 'global' }"><i class="fas fa-globe icon"></i>{{ $ts._timelines.global }}</MkA>
2021-02-16 10:21:44 +01:00
</div>
</div>
<div class="container" v-if="followedChannels">
<div class="header">{{ $ts.channel }} ({{ $ts.following }})<button class="_button add" @click="addChannel"><i class="fas fa-plus"></i></button></div>
2021-02-16 10:21:44 +01:00
<div class="body">
<MkA v-for="channel in followedChannels" :key="channel.id" :to="`/channels/${ channel.id }`" class="item" :class="{ active: tl === `channel:${ channel.id }`, read: !channel.hasUnreadNote }"><i class="fas fa-satellite-dish icon"></i>{{ channel.name }}</MkA>
2021-02-16 10:21:44 +01:00
</div>
</div>
<div class="container" v-if="featuredChannels">
<div class="header">{{ $ts.channel }}<button class="_button add" @click="addChannel"><i class="fas fa-plus"></i></button></div>
2021-02-16 10:21:44 +01:00
<div class="body">
<MkA v-for="channel in featuredChannels" :key="channel.id" :to="`/channels/${ channel.id }`" class="item" :class="{ active: tl === `channel:${ channel.id }` }"><i class="fas fa-satellite-dish icon"></i>{{ channel.name }}</MkA>
</div>
</div>
<div class="container" v-if="lists">
<div class="header">{{ $ts.lists }}<button class="_button add" @click="addList"><i class="fas fa-plus"></i></button></div>
<div class="body">
<MkA v-for="list in lists" :key="list.id" :to="`/my/list/${ list.id }`" class="item" :class="{ active: tl === `list:${ list.id }` }"><i class="fas fa-list-ul icon"></i>{{ list.name }}</MkA>
</div>
</div>
<div class="container" v-if="antennas">
<div class="header">{{ $ts.antennas }}<button class="_button add" @click="addAntenna"><i class="fas fa-plus"></i></button></div>
<div class="body">
<MkA v-for="antenna in antennas" :key="antenna.id" :to="`/my/antenna/${ antenna.id }`" class="item" :class="{ active: tl === `antenna:${ antenna.id }` }"><i class="fas fa-satellite icon"></i>{{ antenna.name }}</MkA>
</div>
</div>
2021-02-16 10:21:44 +01:00
<div class="container">
<div class="body">
<MkA to="/my/favorites" class="item"><i class="fas fa-star icon"></i>{{ $ts.favorites }}</MkA>
</div>
</div>
2021-08-10 17:21:48 +02:00
<MkAd class="a" :prefer="['square']"/>
</div>
<footer class="footer">
<div class="left">
<button class="_button menu" @click="showMenu">
<i class="fas fa-bars icon"></i>
</button>
</div>
<div class="right">
2021-02-16 14:17:13 +01:00
<button class="_button item search" @click="search" v-tooltip="$ts.search">
2021-07-28 07:46:25 +02:00
<i class="fas fa-search icon"></i>
2021-02-16 10:21:44 +01:00
</button>
<MkA class="item" to="/settings" v-tooltip="$ts.settings"><i class="fas fa-cog icon"></i></MkA>
</div>
</footer>
</div>
<main class="main" @contextmenu.stop="onContextmenu">
2021-08-07 12:19:31 +02:00
<header class="header">
<XHeader class="header" :info="pageInfo" :menu="menu" :center="false" :back-button="true" @back="back()" @click="onHeaderClick"/>
</header>
2021-08-07 12:19:31 +02:00
<router-view v-slot="{ Component }">
<transition :name="$store.state.animation ? 'page' : ''" mode="out-in" @enter="onTransition">
<keep-alive :include="['timeline']">
<component :is="Component" :ref="changePage" class="body"/>
</keep-alive>
</transition>
</router-view>
</main>
2021-02-16 14:49:37 +01:00
<XSide class="side" ref="side" @open="sideViewOpening = true" @close="sideViewOpening = false"/>
<div class="side widgets" :class="{ sideViewOpening }">
2021-02-16 14:17:13 +01:00
<XWidgets/>
</div>
<XCommon/>
</div>
</template>
<script lang="ts">
import { defineComponent, defineAsyncComponent } from 'vue';
2021-03-23 09:30:14 +01:00
import { instanceName, url } from '@client/config';
import XSidebar from '@client/ui/_common_/sidebar.vue';
2021-02-16 14:17:13 +01:00
import XWidgets from './widgets.vue';
import XCommon from '../_common_/common.vue';
import XSide from './side.vue';
2021-08-07 12:19:31 +02:00
import XHeader from '../_common_/header.vue';
2021-02-15 09:17:19 +01:00
import XHeaderClock from './header-clock.vue';
2021-03-23 09:30:14 +01:00
import * as os from '@client/os';
import { router } from '@client/router';
2021-07-19 04:36:35 +02:00
import { menuDef } from '@client/menu';
2021-03-23 09:30:14 +01:00
import { search } from '@client/scripts/search';
import copyToClipboard from '@client/scripts/copy-to-clipboard';
import { store } from './store';
2021-08-07 12:19:31 +02:00
import * as symbols from '@client/symbols';
export default defineComponent({
components: {
XCommon,
XSidebar,
2021-02-16 14:17:13 +01:00
XWidgets,
XSide, // NOTE: dynamic importするとAsyncComponentWrapperが間に入るせいでref取得できなくて面倒になる
2021-08-07 12:19:31 +02:00
XHeader,
2021-02-15 09:17:19 +01:00
XHeaderClock,
},
provide() {
return {
sideViewHook: (path) => {
this.$refs.side.navigate(path);
}
};
},
data() {
return {
2021-08-07 12:19:31 +02:00
pageInfo: null,
lists: null,
antennas: null,
followedChannels: null,
featuredChannels: null,
2021-02-15 13:00:37 +01:00
currentChannel: null,
2021-07-19 04:36:35 +02:00
menuDef: menuDef,
2021-02-16 14:49:37 +01:00
sideViewOpening: false,
2021-02-16 14:17:13 +01:00
instanceName,
};
},
2021-08-07 12:19:31 +02:00
computed: {
menu() {
return [{
icon: 'fas fa-columns',
text: this.$ts.openInSideView,
action: () => {
this.$refs.side.navigate(this.$route.path);
}
}, {
icon: 'fas fa-window-maximize',
text: this.$ts.openInWindow,
action: () => {
os.pageWindow(this.$route.path);
}
}];
}
},
created() {
2021-02-17 13:27:11 +01:00
if (window.innerWidth < 1024) {
localStorage.setItem('ui', 'default');
location.reload();
}
os.api('users/lists/list').then(lists => {
this.lists = lists;
});
os.api('antennas/list').then(antennas => {
this.antennas = antennas;
});
os.api('channels/followed', { limit: 20 }).then(channels => {
this.followedChannels = channels;
});
// TODO: pagination
os.api('channels/featured', { limit: 20 }).then(channels => {
this.featuredChannels = channels;
});
},
methods: {
2021-08-07 12:19:31 +02:00
changePage(page) {
console.log(page);
if (page == null) return;
if (page[symbols.PAGE_INFO]) {
this.pageInfo = page[symbols.PAGE_INFO];
document.title = `${this.pageInfo.title} | ${instanceName}`;
}
},
onTransition() {
if (window._scroll) window._scroll();
},
showMenu() {
this.$refs.menu.show();
},
post() {
os.post();
},
2021-02-16 05:13:42 +01:00
search() {
search();
},
2021-08-07 12:19:31 +02:00
back() {
history.back();
2021-02-19 13:40:09 +01:00
},
top() {
window.scroll({ top: 0, behavior: 'smooth' });
},
onTransition() {
if (window._scroll) window._scroll();
},
onHeaderClick() {
window.scroll({ top: 0, behavior: 'smooth' });
},
onContextmenu(e) {
const isLink = (el: HTMLElement) => {
if (el.tagName === 'A') return true;
if (el.parentElement) {
return isLink(el.parentElement);
}
};
if (isLink(e.target)) return;
2021-04-29 05:31:47 +02:00
if (['INPUT', 'TEXTAREA', 'IMG', 'VIDEO', 'CANVAS'].includes(e.target.tagName) || e.target.attributes['contenteditable']) return;
if (window.getSelection().toString() !== '') return;
const path = this.$route.path;
os.contextMenu([{
type: 'label',
text: path,
}, {
icon: 'fas fa-columns',
text: this.$ts.openInSideView,
action: () => {
this.$refs.side.navigate(path);
}
}, {
icon: 'fas fa-window-maximize',
text: this.$ts.openInWindow,
action: () => {
os.pageWindow(path);
}
}], e);
},
}
});
</script>
<style lang="scss" scoped>
.mk-app {
$header-height: 54px; // TODO: どこかに集約したい
$ui-font-size: 1em; // TODO: どこかに集約したい
// ほんとは単に 100vh と書きたいところだが... https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
2021-02-16 14:17:13 +01:00
height: calc(var(--vh, 1vh) * 100);
display: flex;
> .nav {
display: flex;
flex-direction: column;
width: 250px;
height: 100vh;
2021-07-29 16:59:45 +02:00
border-right: solid 4px var(--divider);
> .header, > .footer {
$padding: 8px;
display: flex;
2021-02-16 10:21:44 +01:00
align-items: center;
z-index: 1000;
height: $header-height;
padding: $padding;
box-sizing: border-box;
user-select: none;
&.header {
border-bottom: solid 0.5px var(--divider);
}
&.footer {
border-top: solid 0.5px var(--divider);
}
2021-02-15 09:17:19 +01:00
> .left, > .right {
> .item, > .menu {
2021-07-28 07:46:25 +02:00
display: inline-flex;
2021-02-16 10:21:44 +01:00
vertical-align: middle;
height: ($header-height - ($padding * 2));
width: ($header-height - ($padding * 2));
box-sizing: border-box;
2021-02-14 14:52:45 +01:00
//opacity: 0.6;
position: relative;
2021-02-16 10:21:44 +01:00
border-radius: 5px;
&:hover {
background: rgba(0, 0, 0, 0.05);
}
> .icon {
margin: auto;
}
2021-02-14 14:52:45 +01:00
> .indicator {
2021-02-14 14:52:45 +01:00
position: absolute;
top: 8px;
right: 8px;
color: var(--indicator);
font-size: 8px;
line-height: 8px;
animation: blink 1s infinite;
}
}
}
2021-02-15 09:17:19 +01:00
> .left {
2021-02-16 10:21:44 +01:00
flex: 1;
min-width: 0;
2021-02-15 09:17:19 +01:00
> .account {
display: flex;
align-items: center;
padding: 0 8px;
> .avatar {
width: 26px;
height: 26px;
margin-right: 8px;
}
2021-02-16 10:21:44 +01:00
> .text {
white-space: nowrap;
overflow: hidden;
2021-02-16 10:21:44 +01:00
text-overflow: ellipsis;
font-size: 0.9em;
}
2021-02-15 09:17:19 +01:00
}
}
> .right {
margin-left: auto;
}
}
> .body {
flex: 1;
min-width: 0;
overflow: auto;
> .container {
2021-02-17 13:27:11 +01:00
margin-top: 8px;
margin-bottom: 8px;
& + .container {
margin-top: 16px;
}
> .header {
2021-02-15 13:00:37 +01:00
display: flex;
font-size: 0.9em;
padding: 8px 16px;
2021-02-17 13:27:11 +01:00
position: sticky;
top: 0;
background: var(--X17);
2021-08-11 15:34:45 +02:00
-webkit-backdrop-filter: var(--blur, blur(8px));
backdrop-filter: var(--blur, blur(8px));
2021-02-17 13:27:11 +01:00
z-index: 1;
color: var(--fgTransparentWeak);
2021-02-15 13:00:37 +01:00
> .add {
margin-left: auto;
2021-02-17 13:27:11 +01:00
color: var(--fgTransparentWeak);
&:hover {
color: var(--fg);
}
2021-02-15 13:00:37 +01:00
}
}
> .body {
padding: 0 8px;
> .item {
display: block;
padding: 6px 8px;
border-radius: 4px;
2021-02-20 13:50:58 +01:00
white-space: nowrap;
overflow: hidden;
2021-02-20 13:50:58 +01:00
text-overflow: ellipsis;
&:hover {
text-decoration: none;
background: rgba(0, 0, 0, 0.05);
}
&.active, &.active:hover {
background: var(--accent);
2021-02-17 13:27:11 +01:00
color: #fff !important;
}
&.read {
2021-02-17 13:27:11 +01:00
color: var(--fgTransparent);
}
> .icon {
2021-02-15 13:00:37 +01:00
margin-right: 8px;
opacity: 0.6;
}
}
}
}
2021-07-29 16:59:45 +02:00
> .a {
margin: 12px;
}
}
}
> .main {
display: flex;
flex: 1;
flex-direction: column;
min-width: 0;
height: 100vh;
position: relative;
background: var(--panel);
> .header {
z-index: 1000;
height: $header-height;
2021-02-14 14:54:28 +01:00
background-color: var(--panel);
border-bottom: solid 0.5px var(--divider);
user-select: none;
2021-08-07 12:19:31 +02:00
}
2021-08-07 12:19:31 +02:00
> .body {
width: 100%;
box-sizing: border-box;
overflow: auto;
}
}
> .side {
2021-02-16 14:17:13 +01:00
width: 350px;
2021-07-29 16:59:45 +02:00
border-left: solid 4px var(--divider);
2021-08-07 12:19:31 +02:00
background: var(--panel);
2021-02-16 14:49:37 +01:00
&.widgets.sideViewOpening {
@media (max-width: 1400px) {
display: none;
}
}
}
}
</style>