2018-07-06 18:15:15 +00:00
|
|
|
<template>
|
2020-02-10 15:43:39 +00:00
|
|
|
<div v-if="$store.state.networks.length === 0" class="empty">
|
2018-07-06 18:15:15 +00:00
|
|
|
You are not connected to any networks yet.
|
|
|
|
</div>
|
2020-01-22 16:42:31 +00:00
|
|
|
<div v-else ref="networklist">
|
2019-11-26 20:50:40 +00:00
|
|
|
<div class="jump-to-input">
|
|
|
|
<input
|
|
|
|
ref="searchInput"
|
|
|
|
:value="searchText"
|
|
|
|
placeholder="Jump to..."
|
|
|
|
type="search"
|
|
|
|
class="search input mousetrap"
|
|
|
|
aria-label="Search among the channel list"
|
|
|
|
tabindex="-1"
|
|
|
|
@input="setSearchText"
|
|
|
|
@keydown.up="navigateResults($event, -1)"
|
|
|
|
@keydown.down="navigateResults($event, 1)"
|
|
|
|
@keydown.page-up="navigateResults($event, -10)"
|
|
|
|
@keydown.page-down="navigateResults($event, 10)"
|
|
|
|
@keydown.enter="selectResult"
|
|
|
|
@keydown.escape="deactivateSearch"
|
|
|
|
@focus="activateSearch"
|
2019-02-25 05:38:13 +00:00
|
|
|
/>
|
2019-11-26 20:50:40 +00:00
|
|
|
</div>
|
|
|
|
<div v-if="searchText" class="jump-to-results">
|
2020-01-22 16:42:31 +00:00
|
|
|
<div v-if="results.length">
|
2019-11-26 20:50:40 +00:00
|
|
|
<div
|
|
|
|
v-for="item in results"
|
|
|
|
:key="item.channel.id"
|
2020-01-22 16:42:31 +00:00
|
|
|
@mouseenter="setActiveSearchItem(item.channel)"
|
2019-11-26 20:50:40 +00:00
|
|
|
@click.prevent="selectResult"
|
|
|
|
>
|
|
|
|
<Channel
|
|
|
|
v-if="item.channel.type !== 'lobby'"
|
|
|
|
:channel="item.channel"
|
|
|
|
:network="item.network"
|
|
|
|
:active="item.channel === activeSearchItem"
|
|
|
|
:is-filtering="true"
|
|
|
|
/>
|
|
|
|
<NetworkLobby
|
|
|
|
v-else
|
|
|
|
:channel="item.channel"
|
|
|
|
:network="item.network"
|
|
|
|
:active="item.channel === activeSearchItem"
|
|
|
|
:is-filtering="true"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-else class="no-results">
|
|
|
|
No results found.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Draggable
|
|
|
|
v-else
|
2020-02-10 15:43:39 +00:00
|
|
|
:list="$store.state.networks"
|
2019-11-26 20:50:40 +00:00
|
|
|
:filter="isCurrentlyInTouch"
|
|
|
|
:prevent-on-filter="false"
|
|
|
|
handle=".channel-list-item[data-type='lobby']"
|
|
|
|
draggable=".network"
|
|
|
|
ghost-class="ui-sortable-ghost"
|
|
|
|
drag-class="ui-sortable-dragged"
|
|
|
|
group="networks"
|
|
|
|
class="networks"
|
|
|
|
@change="onNetworkSort"
|
|
|
|
@start="onDragStart"
|
|
|
|
@end="onDragEnd"
|
|
|
|
>
|
|
|
|
<div
|
2020-02-10 15:43:39 +00:00
|
|
|
v-for="network in $store.state.networks"
|
2019-11-26 20:50:40 +00:00
|
|
|
:id="'network-' + network.uuid"
|
|
|
|
:key="network.uuid"
|
|
|
|
:class="{
|
|
|
|
collapsed: network.isCollapsed,
|
|
|
|
'not-connected': !network.status.connected,
|
|
|
|
'not-secure': !network.status.secure,
|
|
|
|
}"
|
|
|
|
class="network"
|
|
|
|
role="region"
|
2019-02-25 05:38:13 +00:00
|
|
|
>
|
2019-11-26 20:50:40 +00:00
|
|
|
<NetworkLobby
|
2018-07-06 18:15:15 +00:00
|
|
|
:network="network"
|
2019-11-26 20:50:40 +00:00
|
|
|
:is-join-channel-shown="network.isJoinChannelShown"
|
2020-02-10 15:43:39 +00:00
|
|
|
:active="
|
|
|
|
$store.state.activeChannel &&
|
2020-03-21 20:55:36 +00:00
|
|
|
network.channels[0] === $store.state.activeChannel.channel
|
2020-02-10 15:43:39 +00:00
|
|
|
"
|
2019-11-26 20:50:40 +00:00
|
|
|
@toggleJoinChannel="network.isJoinChannelShown = !network.isJoinChannelShown"
|
2019-02-25 05:38:13 +00:00
|
|
|
/>
|
2019-11-26 20:50:40 +00:00
|
|
|
<JoinChannel
|
|
|
|
v-if="network.isJoinChannelShown"
|
|
|
|
:network="network"
|
|
|
|
:channel="network.channels[0]"
|
|
|
|
@toggleJoinChannel="network.isJoinChannelShown = !network.isJoinChannelShown"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Draggable
|
|
|
|
draggable=".channel-list-item"
|
|
|
|
ghost-class="ui-sortable-ghost"
|
|
|
|
drag-class="ui-sortable-dragged"
|
|
|
|
:group="network.uuid"
|
|
|
|
:filter="isCurrentlyInTouch"
|
|
|
|
:prevent-on-filter="false"
|
|
|
|
:list="network.channels"
|
|
|
|
class="channels"
|
|
|
|
@change="onChannelSort"
|
|
|
|
@start="onDragStart"
|
|
|
|
@end="onDragEnd"
|
|
|
|
>
|
2020-04-28 14:27:09 +00:00
|
|
|
<template v-for="(channel, index) in network.channels">
|
|
|
|
<Channel
|
|
|
|
v-if="index > 0"
|
|
|
|
:key="channel.id"
|
|
|
|
:channel="channel"
|
|
|
|
:network="network"
|
|
|
|
:active="
|
|
|
|
$store.state.activeChannel &&
|
|
|
|
channel === $store.state.activeChannel.channel
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
</template>
|
2019-11-26 20:50:40 +00:00
|
|
|
</Draggable>
|
|
|
|
</div>
|
|
|
|
</Draggable>
|
|
|
|
</div>
|
2018-07-06 18:15:15 +00:00
|
|
|
</template>
|
|
|
|
|
2020-01-11 15:40:18 +00:00
|
|
|
<style>
|
|
|
|
.jump-to-input {
|
|
|
|
margin: 8px;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.jump-to-input .input {
|
|
|
|
margin: 0;
|
|
|
|
width: 100%;
|
|
|
|
border: 0;
|
2020-01-22 16:42:31 +00:00
|
|
|
color: #fff;
|
2020-01-11 15:40:18 +00:00
|
|
|
background-color: rgba(255, 255, 255, 0.1);
|
|
|
|
padding-right: 35px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.jump-to-input .input::placeholder {
|
|
|
|
color: rgba(255, 255, 255, 0.35);
|
|
|
|
}
|
|
|
|
|
|
|
|
.jump-to-input::before {
|
|
|
|
content: "\f002"; /* http://fontawesome.io/icon/search/ */
|
|
|
|
color: rgba(255, 255, 255, 0.35);
|
|
|
|
position: absolute;
|
|
|
|
right: 8px;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
|
|
|
pointer-events: none;
|
|
|
|
line-height: 35px !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.jump-to-results {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
list-style: none;
|
|
|
|
overflow: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.jump-to-results .no-results {
|
|
|
|
margin: 14px 8px;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.jump-to-results .channel-list-item.active {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.jump-to-results .channel-list-item .add-channel,
|
|
|
|
.jump-to-results .channel-list-item .close-tooltip {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.jump-to-results .channel-list-item[data-type="lobby"] {
|
|
|
|
padding: 8px 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.jump-to-results .channel-list-item[data-type="lobby"]::before {
|
|
|
|
content: "\f233";
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2018-07-06 18:15:15 +00:00
|
|
|
<script>
|
2020-01-02 20:41:52 +00:00
|
|
|
import Mousetrap from "mousetrap";
|
2018-07-06 18:15:15 +00:00
|
|
|
import Draggable from "vuedraggable";
|
2019-11-26 20:50:40 +00:00
|
|
|
import {filter as fuzzyFilter} from "fuzzy";
|
2018-07-12 19:24:35 +00:00
|
|
|
import NetworkLobby from "./NetworkLobby.vue";
|
2018-07-06 18:15:15 +00:00
|
|
|
import Channel from "./Channel.vue";
|
2018-07-12 19:24:35 +00:00
|
|
|
import JoinChannel from "./JoinChannel.vue";
|
2018-07-06 18:15:15 +00:00
|
|
|
|
|
|
|
import socket from "../js/socket";
|
2020-01-02 20:41:52 +00:00
|
|
|
import collapseNetwork from "../js/helpers/collapseNetwork";
|
2020-03-17 10:00:33 +00:00
|
|
|
import isIgnoredKeybind from "../js/helpers/isIgnoredKeybind";
|
2018-07-06 18:15:15 +00:00
|
|
|
|
|
|
|
export default {
|
2018-07-12 19:24:35 +00:00
|
|
|
name: "NetworkList",
|
2018-07-06 18:15:15 +00:00
|
|
|
components: {
|
|
|
|
JoinChannel,
|
2018-07-12 19:24:35 +00:00
|
|
|
NetworkLobby,
|
2018-07-06 18:15:15 +00:00
|
|
|
Channel,
|
|
|
|
Draggable,
|
|
|
|
},
|
2019-11-26 20:50:40 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
searchText: "",
|
|
|
|
activeSearchItem: null,
|
|
|
|
};
|
|
|
|
},
|
2019-11-02 19:40:59 +00:00
|
|
|
computed: {
|
2019-11-26 20:50:40 +00:00
|
|
|
items() {
|
|
|
|
const items = [];
|
|
|
|
|
|
|
|
for (const network of this.$store.state.networks) {
|
|
|
|
for (const channel of network.channels) {
|
|
|
|
if (
|
|
|
|
this.$store.state.activeChannel &&
|
|
|
|
channel === this.$store.state.activeChannel.channel
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
items.push({network, channel});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
},
|
|
|
|
results() {
|
|
|
|
const results = fuzzyFilter(this.searchText, this.items, {
|
|
|
|
extract: (item) => item.channel.name,
|
|
|
|
}).map((item) => item.original);
|
|
|
|
|
|
|
|
return results;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
searchText() {
|
|
|
|
this.setActiveSearchItem();
|
|
|
|
},
|
|
|
|
},
|
2020-01-02 20:41:52 +00:00
|
|
|
mounted() {
|
|
|
|
Mousetrap.bind("alt+shift+right", this.expandNetwork);
|
|
|
|
Mousetrap.bind("alt+shift+left", this.collapseNetwork);
|
2020-01-11 15:40:18 +00:00
|
|
|
Mousetrap.bind("alt+j", this.toggleSearch);
|
2020-01-02 20:41:52 +00:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
Mousetrap.unbind("alt+shift+right", this.expandNetwork);
|
|
|
|
Mousetrap.unbind("alt+shift+left", this.collapseNetwork);
|
2020-01-11 15:40:18 +00:00
|
|
|
Mousetrap.unbind("alt+j", this.toggleSearch);
|
2020-01-02 20:41:52 +00:00
|
|
|
},
|
2019-07-12 10:43:47 +00:00
|
|
|
methods: {
|
2020-03-17 10:00:33 +00:00
|
|
|
expandNetwork(event) {
|
|
|
|
if (isIgnoredKeybind(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-02 20:41:52 +00:00
|
|
|
if (this.$store.state.activeChannel) {
|
|
|
|
collapseNetwork(this.$store.state.activeChannel.network, false);
|
|
|
|
}
|
2020-03-17 10:00:33 +00:00
|
|
|
|
|
|
|
return false;
|
2020-01-02 20:41:52 +00:00
|
|
|
},
|
2020-03-17 10:00:33 +00:00
|
|
|
collapseNetwork(event) {
|
|
|
|
if (isIgnoredKeybind(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-02 20:41:52 +00:00
|
|
|
if (this.$store.state.activeChannel) {
|
|
|
|
collapseNetwork(this.$store.state.activeChannel.network, true);
|
|
|
|
}
|
2020-03-17 10:00:33 +00:00
|
|
|
|
|
|
|
return false;
|
2020-01-02 20:41:52 +00:00
|
|
|
},
|
2019-07-12 10:43:47 +00:00
|
|
|
isCurrentlyInTouch(e) {
|
2018-08-30 18:12:53 +00:00
|
|
|
// TODO: Implement a way to sort on touch devices
|
2019-07-12 10:43:47 +00:00
|
|
|
return e.pointerType !== "mouse";
|
2018-08-30 18:12:53 +00:00
|
|
|
},
|
2018-07-06 18:15:15 +00:00
|
|
|
onDragStart(e) {
|
2019-03-19 13:11:44 +00:00
|
|
|
e.target.classList.add("ui-sortable-active");
|
2018-07-06 18:15:15 +00:00
|
|
|
},
|
|
|
|
onDragEnd(e) {
|
2019-03-19 13:11:44 +00:00
|
|
|
e.target.classList.remove("ui-sortable-active");
|
2018-07-06 18:15:15 +00:00
|
|
|
},
|
|
|
|
onNetworkSort(e) {
|
|
|
|
if (!e.moved) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
socket.emit("sort", {
|
|
|
|
type: "networks",
|
2020-02-10 15:43:39 +00:00
|
|
|
order: this.$store.state.networks.map((n) => n.uuid),
|
2018-07-06 18:15:15 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
onChannelSort(e) {
|
|
|
|
if (!e.moved) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-03 14:59:43 +00:00
|
|
|
const channel = this.$store.getters.findChannel(e.moved.element.id);
|
2018-07-06 18:15:15 +00:00
|
|
|
|
|
|
|
if (!channel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
socket.emit("sort", {
|
|
|
|
type: "channels",
|
|
|
|
target: channel.network.uuid,
|
|
|
|
order: channel.network.channels.map((c) => c.id),
|
|
|
|
});
|
|
|
|
},
|
2019-11-26 20:50:40 +00:00
|
|
|
toggleSearch(event) {
|
2020-03-17 10:00:33 +00:00
|
|
|
if (isIgnoredKeybind(event)) {
|
2020-01-22 16:42:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-11-26 20:50:40 +00:00
|
|
|
|
|
|
|
if (this.$refs.searchInput === document.activeElement) {
|
2020-01-22 16:42:31 +00:00
|
|
|
this.deactivateSearch();
|
|
|
|
return false;
|
2019-11-26 20:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.activateSearch();
|
2020-01-22 16:42:31 +00:00
|
|
|
return false;
|
2019-11-26 20:50:40 +00:00
|
|
|
},
|
|
|
|
activateSearch() {
|
|
|
|
if (this.$refs.searchInput === document.activeElement) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-22 16:42:31 +00:00
|
|
|
this.sidebarWasClosed = this.$store.state.sidebarOpen ? false : true;
|
2019-11-26 20:50:40 +00:00
|
|
|
this.$store.commit("sidebarOpen", true);
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.searchInput.focus();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
deactivateSearch() {
|
|
|
|
this.activeSearchItem = null;
|
|
|
|
this.searchText = "";
|
|
|
|
this.$refs.searchInput.blur();
|
|
|
|
|
2020-01-22 16:42:31 +00:00
|
|
|
if (this.sidebarWasClosed) {
|
2019-11-26 20:50:40 +00:00
|
|
|
this.$store.commit("sidebarOpen", false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setSearchText(e) {
|
|
|
|
this.searchText = e.target.value;
|
|
|
|
},
|
|
|
|
setActiveSearchItem(channel) {
|
|
|
|
if (!this.results.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!channel) {
|
|
|
|
channel = this.results[0].channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.activeSearchItem = channel;
|
|
|
|
},
|
|
|
|
selectResult() {
|
|
|
|
if (!this.searchText || !this.results.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$root.switchToChannel(this.activeSearchItem);
|
|
|
|
this.deactivateSearch();
|
2020-01-22 16:42:31 +00:00
|
|
|
this.scrollToActive();
|
2019-11-26 20:50:40 +00:00
|
|
|
},
|
|
|
|
navigateResults(event, direction) {
|
|
|
|
// Prevent propagation to stop global keybind handler from capturing pagedown/pageup
|
|
|
|
// and redirecting it to the message list container for scrolling
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (!this.searchText) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const channels = this.results.map((r) => r.channel);
|
|
|
|
|
|
|
|
// Bail out if there's no channels to select
|
|
|
|
if (!channels.length) {
|
|
|
|
this.activeSearchItem = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let currentIndex = channels.indexOf(this.activeSearchItem);
|
|
|
|
|
|
|
|
// If there's no active channel select the first or last one depending on direction
|
|
|
|
if (!this.activeSearchItem || currentIndex === -1) {
|
|
|
|
this.activeSearchItem = direction ? channels[0] : channels[channels.length - 1];
|
|
|
|
this.scrollToActive();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentIndex += direction;
|
|
|
|
|
|
|
|
// Wrap around the list if necessary. Normaly each loop iterates once at most,
|
|
|
|
// but might iterate more often if pgup or pgdown are used in a very short list
|
|
|
|
while (currentIndex < 0) {
|
|
|
|
currentIndex += channels.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currentIndex > channels.length - 1) {
|
|
|
|
currentIndex -= channels.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.activeSearchItem = channels[currentIndex];
|
|
|
|
this.scrollToActive();
|
|
|
|
},
|
|
|
|
scrollToActive() {
|
|
|
|
// Scroll the list if needed after the active class is applied
|
|
|
|
this.$nextTick(() => {
|
2020-01-22 16:42:31 +00:00
|
|
|
const el = this.$refs.networklist.querySelector(".channel-list-item.active");
|
2019-11-26 20:50:40 +00:00
|
|
|
|
|
|
|
if (el) {
|
|
|
|
el.scrollIntoView({block: "nearest", inline: "nearest"});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2018-07-06 18:15:15 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|