Implement closeChannel method.

This commit is contained in:
Richard Lewis 2019-11-23 16:44:23 +00:00 committed by Pavel Djundik
parent 0c49f025b4
commit dca6543070
5 changed files with 19 additions and 36 deletions

View File

@ -44,7 +44,7 @@ export default {
}, },
methods: { methods: {
close() { close() {
this.$refs.wrapper.close(); this.$root.closeChannel(this.channel);
}, },
}, },
}; };

View File

@ -14,7 +14,7 @@
:data-name="channel.name" :data-name="channel.name"
:aria-controls="'#chan-' + channel.id" :aria-controls="'#chan-' + channel.id"
:aria-selected="activeChannel && channel === activeChannel.channel" :aria-selected="activeChannel && channel === activeChannel.channel"
:style="closed ? {transition: 'none', opacity: 0.4} : null" :style="channel.closed ? {transition: 'none', opacity: 0.4} : null"
role="tab" role="tab"
@click="click" @click="click"
@contextmenu.prevent="openContextMenu" @contextmenu.prevent="openContextMenu"
@ -24,7 +24,6 @@
</template> </template>
<script> <script>
import socket from "../js/socket";
import isChannelCollapsed from "../js/helpers/isChannelCollapsed"; import isChannelCollapsed from "../js/helpers/isChannelCollapsed";
export default { export default {
@ -33,11 +32,6 @@ export default {
network: Object, network: Object,
channel: Object, channel: Object,
}, },
data() {
return {
closed: false,
};
},
computed: { computed: {
activeChannel() { activeChannel() {
return this.$store.state.activeChannel; return this.$store.state.activeChannel;
@ -47,14 +41,6 @@ export default {
}, },
}, },
methods: { methods: {
close() {
this.closed = true;
socket.emit("input", {
target: Number(this.channel.id),
text: "/close",
});
},
getAriaLabel() { getAriaLabel() {
const extra = []; const extra = [];

View File

@ -42,14 +42,12 @@
@click.stop="$emit('toggleJoinChannel')" @click.stop="$emit('toggleJoinChannel')"
/> />
</span> </span>
<button class="close" hidden @click.stop="close" />
</ChannelWrapper> </ChannelWrapper>
</template> </template>
<script> <script>
import roundBadgeNumber from "../js/helpers/roundBadgeNumber"; import roundBadgeNumber from "../js/helpers/roundBadgeNumber";
import ChannelWrapper from "./ChannelWrapper.vue"; import ChannelWrapper from "./ChannelWrapper.vue";
import socket from "../js/socket";
import storage from "../js/localStorage"; import storage from "../js/localStorage";
export default { export default {
@ -73,17 +71,6 @@ export default {
}, },
}, },
methods: { methods: {
close() {
// eslint-disable-next-line no-alert
if (!confirm(`Are you sure you want to remove ${this.channel.name}?`)) {
return false;
}
socket.emit("input", {
target: Number(this.channel.id),
text: "/quit",
});
},
onCollapseClick() { onCollapseClick() {
const networks = new Set(JSON.parse(storage.get("thelounge.networks.collapsed"))); const networks = new Set(JSON.parse(storage.get("thelounge.networks.collapsed")));
this.network.isCollapsed = !this.network.isCollapsed; this.network.isCollapsed = !this.network.isCollapsed;

View File

@ -139,13 +139,7 @@ export function generateChannelContextMenu($root, channel, network) {
type: "item", type: "item",
class: "close", class: "close",
action() { action() {
const close = document.querySelector( $root.closeChannel(channel);
`.networks .chan[data-target="#chan-${channel.id}"] .close`
);
if (close) {
close.click();
}
}, },
}); });

View File

@ -29,6 +29,22 @@ const vueApp = new Vue({
switchToChannel(channel) { switchToChannel(channel) {
navigate("RoutedChat", {id: channel.id}); navigate("RoutedChat", {id: channel.id});
}, },
closeChannel(channel) {
if (
channel.type === "lobby" &&
// eslint-disable-next-line no-alert
!confirm(`Are you sure you want to remove ${channel.name}?`)
) {
return false;
}
channel.closed = true;
socket.emit("input", {
target: Number(channel.id),
text: channel.type === "lobby" ? "/quit" : "/close",
});
},
}, },
render(createElement) { render(createElement) {
return createElement(App, { return createElement(App, {