2019-02-22 14:21:32 +00:00
|
|
|
<template>
|
2019-08-05 14:35:53 +00:00
|
|
|
<aside id="sidebar" ref="sidebar">
|
|
|
|
<div class="scrollable-area">
|
|
|
|
<div class="logo-container">
|
|
|
|
<img
|
|
|
|
:src="`img/logo-${isPublic() ? 'horizontal-' : ''}transparent-bg.svg`"
|
|
|
|
class="logo"
|
2023-10-05 04:16:57 +00:00
|
|
|
alt="SuperNETs"
|
2021-04-21 01:04:31 +00:00
|
|
|
role="presentation"
|
2019-08-05 14:35:53 +00:00
|
|
|
/>
|
|
|
|
<img
|
|
|
|
:src="`img/logo-${isPublic() ? 'horizontal-' : ''}transparent-bg-inverted.svg`"
|
|
|
|
class="logo-inverted"
|
2023-10-05 04:16:57 +00:00
|
|
|
alt="SuperNETs"
|
2021-04-21 01:04:31 +00:00
|
|
|
role="presentation"
|
2019-08-05 14:35:53 +00:00
|
|
|
/>
|
2019-11-25 18:53:22 +00:00
|
|
|
<span
|
|
|
|
v-if="isDevelopment"
|
|
|
|
title="The Lounge has been built in development mode"
|
|
|
|
:style="{
|
|
|
|
backgroundColor: '#ff9e18',
|
|
|
|
color: '#000',
|
|
|
|
padding: '2px',
|
|
|
|
borderRadius: '4px',
|
|
|
|
fontSize: '12px',
|
|
|
|
}"
|
|
|
|
>DEVELOPER</span
|
|
|
|
>
|
2019-02-22 14:21:32 +00:00
|
|
|
</div>
|
2019-11-02 19:40:59 +00:00
|
|
|
<NetworkList />
|
2019-08-05 14:35:53 +00:00
|
|
|
</div>
|
|
|
|
<footer id="footer">
|
|
|
|
<span
|
|
|
|
class="tooltipped tooltipped-n tooltipped-no-touch"
|
|
|
|
aria-label="Connect to network"
|
2019-10-20 16:17:21 +00:00
|
|
|
><router-link
|
2022-06-19 00:25:21 +00:00
|
|
|
v-slot:default="{navigate, isActive}"
|
2019-10-20 16:17:21 +00:00
|
|
|
to="/connect"
|
2019-08-05 14:35:53 +00:00
|
|
|
role="tab"
|
|
|
|
aria-controls="connect"
|
2022-06-19 00:25:21 +00:00
|
|
|
>
|
|
|
|
<button
|
|
|
|
:class="['icon', 'connect', {active: isActive}]"
|
|
|
|
:aria-selected="isActive"
|
|
|
|
@click="navigate"
|
|
|
|
@keypress.enter="navigate"
|
|
|
|
/> </router-link
|
|
|
|
></span>
|
2019-08-05 14:35:53 +00:00
|
|
|
<span class="tooltipped tooltipped-n tooltipped-no-touch" aria-label="Settings"
|
2019-10-20 16:17:21 +00:00
|
|
|
><router-link
|
2022-06-19 00:25:21 +00:00
|
|
|
v-slot:default="{navigate, isActive}"
|
2019-10-20 16:17:21 +00:00
|
|
|
to="/settings"
|
2019-08-05 14:35:53 +00:00
|
|
|
role="tab"
|
|
|
|
aria-controls="settings"
|
2022-06-19 00:25:21 +00:00
|
|
|
>
|
|
|
|
<button
|
|
|
|
:class="['icon', 'settings', {active: isActive}]"
|
|
|
|
:aria-selected="isActive"
|
|
|
|
@click="navigate"
|
|
|
|
@keypress.enter="navigate"
|
|
|
|
></button> </router-link
|
|
|
|
></span>
|
2020-01-02 10:55:02 +00:00
|
|
|
<span
|
|
|
|
class="tooltipped tooltipped-n tooltipped-no-touch"
|
|
|
|
:aria-label="
|
2022-06-19 00:25:21 +00:00
|
|
|
store.state.serverConfiguration?.isUpdateAvailable
|
2020-01-02 10:55:02 +00:00
|
|
|
? 'Help\n(update available)'
|
|
|
|
: 'Help'
|
|
|
|
"
|
2019-10-20 16:17:21 +00:00
|
|
|
><router-link
|
2022-06-19 00:25:21 +00:00
|
|
|
v-slot:default="{navigate, isActive}"
|
2019-10-20 16:17:21 +00:00
|
|
|
to="/help"
|
2019-08-05 14:35:53 +00:00
|
|
|
role="tab"
|
|
|
|
aria-controls="help"
|
2022-06-19 00:25:21 +00:00
|
|
|
>
|
|
|
|
<button
|
|
|
|
:aria-selected="route.name === 'Help'"
|
|
|
|
:class="[
|
|
|
|
'icon',
|
|
|
|
'help',
|
|
|
|
{notified: store.state.serverConfiguration?.isUpdateAvailable},
|
|
|
|
{active: isActive},
|
|
|
|
]"
|
|
|
|
@click="navigate"
|
|
|
|
@keypress.enter="navigate"
|
|
|
|
></button> </router-link
|
|
|
|
></span>
|
2019-08-05 14:35:53 +00:00
|
|
|
</footer>
|
|
|
|
</aside>
|
2019-02-22 14:21:32 +00:00
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
2022-12-23 08:50:20 +00:00
|
|
|
import {defineComponent, nextTick, onMounted, onUnmounted, PropType, ref} from "vue";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {useRoute} from "vue-router";
|
|
|
|
import {useStore} from "../js/store";
|
2019-02-22 14:21:32 +00:00
|
|
|
import NetworkList from "./NetworkList.vue";
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2019-02-22 14:21:32 +00:00
|
|
|
name: "Sidebar",
|
|
|
|
components: {
|
|
|
|
NetworkList,
|
|
|
|
},
|
|
|
|
props: {
|
2022-06-19 00:25:21 +00:00
|
|
|
overlay: {type: Object as PropType<HTMLElement | null>, required: true},
|
2019-11-25 18:53:22 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
setup(props) {
|
|
|
|
const isDevelopment = process.env.NODE_ENV !== "production";
|
2019-08-05 12:24:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const store = useStore();
|
|
|
|
const route = useRoute();
|
2019-08-05 12:24:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const touchStartPos = ref<Touch | null>();
|
|
|
|
const touchCurPos = ref<Touch | null>();
|
|
|
|
const touchStartTime = ref<number>(0);
|
|
|
|
const menuWidth = ref<number>(0);
|
|
|
|
const menuIsMoving = ref<boolean>(false);
|
|
|
|
const menuIsAbsolute = ref<boolean>(false);
|
2019-08-05 12:24:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const sidebar = ref<HTMLElement | null>(null);
|
2019-08-05 12:24:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const toggle = (state: boolean) => {
|
|
|
|
store.commit("sidebarOpen", state);
|
|
|
|
};
|
2019-08-05 12:24:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const onTouchMove = (e: TouchEvent) => {
|
|
|
|
const touch = (touchCurPos.value = e.touches.item(0));
|
2019-08-05 12:24:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (
|
|
|
|
!touch ||
|
|
|
|
!touchStartPos.value ||
|
|
|
|
!touchStartPos.value.screenX ||
|
|
|
|
!touchStartPos.value.screenY
|
|
|
|
) {
|
|
|
|
return;
|
2019-08-05 12:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
let distX = touch.screenX - touchStartPos.value.screenX;
|
|
|
|
const distY = touch.screenY - touchStartPos.value.screenY;
|
2019-08-05 12:24:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (!menuIsMoving.value) {
|
2019-08-05 12:24:44 +00:00
|
|
|
// tan(45°) is 1. Gestures in 0°-45° (< 1) are considered horizontal, so
|
|
|
|
// menu must be open; gestures in 45°-90° (>1) are considered vertical, so
|
|
|
|
// chat windows must be scrolled.
|
|
|
|
if (Math.abs(distY / distX) >= 1) {
|
2022-06-19 00:25:21 +00:00
|
|
|
// eslint-disable-next-line no-use-before-define
|
|
|
|
onTouchEnd();
|
2019-08-05 12:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const devicePixelRatio = window.devicePixelRatio || 2;
|
|
|
|
|
|
|
|
if (Math.abs(distX) > devicePixelRatio) {
|
2022-06-19 00:25:21 +00:00
|
|
|
store.commit("sidebarDragging", true);
|
|
|
|
menuIsMoving.value = true;
|
2019-08-05 12:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not animate the menu on desktop view
|
2022-06-19 00:25:21 +00:00
|
|
|
if (!menuIsAbsolute.value) {
|
2019-08-05 12:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (store.state.sidebarOpen) {
|
|
|
|
distX += menuWidth.value;
|
2019-08-05 12:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (distX > menuWidth.value) {
|
|
|
|
distX = menuWidth.value;
|
2019-08-05 12:24:44 +00:00
|
|
|
} else if (distX < 0) {
|
|
|
|
distX = 0;
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (sidebar.value) {
|
|
|
|
sidebar.value.style.transform = "translate3d(" + distX.toString() + "px, 0, 0)";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.overlay) {
|
|
|
|
props.overlay.style.opacity = `${distX / menuWidth.value}`;
|
|
|
|
}
|
2019-08-05 12:24:44 +00:00
|
|
|
};
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const onTouchEnd = () => {
|
|
|
|
if (!touchStartPos.value?.screenX || !touchCurPos.value?.screenX) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const diff = touchCurPos.value.screenX - touchStartPos.value.screenX;
|
2019-08-05 12:24:44 +00:00
|
|
|
const absDiff = Math.abs(diff);
|
|
|
|
|
|
|
|
if (
|
2022-06-19 00:25:21 +00:00
|
|
|
absDiff > menuWidth.value / 2 ||
|
|
|
|
(Date.now() - touchStartTime.value < 180 && absDiff > 50)
|
2019-08-05 12:24:44 +00:00
|
|
|
) {
|
2022-06-19 00:25:21 +00:00
|
|
|
toggle(diff > 0);
|
2019-08-05 12:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
document.body.removeEventListener("touchmove", onTouchMove);
|
|
|
|
document.body.removeEventListener("touchend", onTouchEnd);
|
2019-08-05 12:24:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
store.commit("sidebarDragging", false);
|
2019-08-05 12:24:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
touchStartPos.value = null;
|
|
|
|
touchCurPos.value = null;
|
|
|
|
touchStartTime.value = 0;
|
|
|
|
menuIsMoving.value = false;
|
2022-12-23 08:50:20 +00:00
|
|
|
|
|
|
|
void nextTick(() => {
|
|
|
|
if (sidebar.value) {
|
|
|
|
sidebar.value.style.transform = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.overlay) {
|
|
|
|
props.overlay.style.opacity = "";
|
|
|
|
}
|
|
|
|
});
|
2019-08-05 12:24:44 +00:00
|
|
|
};
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const onTouchStart = (e: TouchEvent) => {
|
|
|
|
if (!sidebar.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
touchStartPos.value = touchCurPos.value = e.touches.item(0);
|
|
|
|
|
|
|
|
if (e.touches.length !== 1) {
|
|
|
|
onTouchEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = window.getComputedStyle(sidebar.value);
|
|
|
|
|
|
|
|
menuWidth.value = parseFloat(styles.width);
|
|
|
|
menuIsAbsolute.value = styles.position === "absolute";
|
|
|
|
|
|
|
|
if (
|
|
|
|
!store.state.sidebarOpen ||
|
|
|
|
(touchStartPos.value?.screenX && touchStartPos.value.screenX > menuWidth.value)
|
|
|
|
) {
|
|
|
|
touchStartTime.value = Date.now();
|
|
|
|
|
|
|
|
document.body.addEventListener("touchmove", onTouchMove, {passive: true});
|
|
|
|
document.body.addEventListener("touchend", onTouchEnd, {passive: true});
|
|
|
|
}
|
2019-08-05 12:24:44 +00:00
|
|
|
};
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
onMounted(() => {
|
|
|
|
document.body.addEventListener("touchstart", onTouchStart, {passive: true});
|
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
document.body.removeEventListener("touchstart", onTouchStart);
|
|
|
|
});
|
|
|
|
|
|
|
|
const isPublic = () => document.body.classList.contains("public");
|
|
|
|
|
|
|
|
return {
|
|
|
|
isDevelopment,
|
|
|
|
store,
|
|
|
|
route,
|
|
|
|
sidebar,
|
|
|
|
toggle,
|
|
|
|
onTouchStart,
|
|
|
|
onTouchMove,
|
|
|
|
onTouchEnd,
|
|
|
|
isPublic,
|
|
|
|
};
|
2019-02-22 14:21:32 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2019-02-22 14:21:32 +00:00
|
|
|
</script>
|