A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
chore: code smells
aminnausind2be6ac852fc
diff --git a/resources/js/components/pinesUI/ToastController.vue b/resources/js/components/pinesUI/ToastController.vueindex 2011ddc3..7e804129 100755--- a/resources/js/components/pinesUI/ToastController.vue+++ b/resources/js/components/pinesUI/ToastController.vue@@ -37,7 +37,10 @@ function deleteToastWithId(id: string) {}function stackToasts(_?: any) {- positionToasts(_);+ if (messages.value.length > 0) {+ positionToasts(_);+ }+calculateHeightOfToastsContainer();if (heightRecalculateTimeout.value) clearTimeout(heightRecalculateTimeout.value);@@ -46,31 +49,23 @@ function stackToasts(_?: any) {if (!expanded.value) return;heightRecalculateTimeout.value = window.setTimeout(() => {- // positionToasts(_);calculateHeightOfToastsContainer();}, 100);}function positionToasts(_?: any) {- if (messages.value.length == 0) {- return;- }-try {- const bottomFlag = position.value.includes('bottom');- const toastElements = [];+ const isBottom = position.value.includes('bottom');+ const toastElements: HTMLElement[] = [];let totalHeight = 0;-let scaleBuffer = 1 + SCALE_STEP;let yBuffer = -Y_OFFSET_STEP;let zBuffer = 200 + Z_STEP;- for (let i = 0; i < messages.value.length; i++) {- const msg = messages.value[i];- const toast = document.getElementById(`${messages.value[i].id}`);-- if (!toast) return;+ for (const msg of messages.value) {+ const toastEl = document.getElementById(msg.id);+ if (!toastEl) return;zBuffer -= Z_STEP;scaleBuffer -= SCALE_STEP;@@ -80,40 +75,31 @@ function positionToasts(_?: any) {msg.offsetY = yBuffer;msg.zIndex = zBuffer;- toast.style.zIndex = `${zBuffer}`;- toastElements.push(toast);+ toastElements.push(toastEl);if (expanded.value) {totalHeight = totalHeight + (totalHeight ? paddingBetweenToasts.value : 0);- if (bottomFlag) {- toast.style.top = 'auto';- toast.style.bottom = totalHeight + 'px';- } else toast.style.top = totalHeight + 'px';+ // if (isBottom) {+ // toastEl.style.top = 'auto';+ // toastEl.style.bottom = totalHeight + 'px';+ msg.positionY = totalHeight + 'px';+ // } else toastEl.style.top = totalHeight + 'px';- totalHeight += toast.offsetHeight;+ totalHeight += toastEl.offsetHeight;- // toast.style.scale = `1`;msg.scale = 1;-msg.offsetY = 0;-- // toast.style.setProperty('--offset-y', '0px');continue;}msg.scale = scaleBuffer;- // toast.style.scale = `${scaleBuffer}`;- if (bottomFlag) {+ if (isBottom) {msg.offsetY *= -1;- // toast.style.setProperty('--offset-y', `-${yBuffer}px`);} else {- alignBottom(toastElements[0], toast);- // toast.style.setProperty('--offset-y', `${yBuffer}px`);+ alignBottom(toastElements[0], msg);}-- Object.assign(messages.value[i], msg);}handleToastsOverflow(toastElements);@@ -183,7 +169,11 @@ function calculateHeightOfToastsContainer() {container.value.style.height = lastToastRectangle.top + lastToastRectangle.height - firstToastRectangle.top + 'px';}-function alignBottom(element1: HTMLElement, element2: HTMLElement) {+function alignBottom(element1: HTMLElement, toast: Message) {+ const element2 = document.getElementById(toast.id);++ if (!element2) return;+// Get the top position and height of the first elementconst top1 = element1.offsetTop;const height1 = element1.offsetHeight;@@ -195,25 +185,7 @@ function alignBottom(element1: HTMLElement, element2: HTMLElement) {const top2 = top1 + (height1 - height2);// Apply the calculated top position to the second element- element2.style.top = top2 + 'px';-}--function resetBottom() {- for (const message of messages.value) {- const toastElement = document.getElementById(`${message?.id}`);- if (toastElement) {- toastElement.style.bottom = '0px';- }- }-}--function resetTop() {- for (const message of messages.value) {- const toastElement = document.getElementById(`${message?.id}`);- if (toastElement) {- toastElement.style.top = '0px';- }- }+ toast.positionY = top2 + 'px';}onMounted(() => {@@ -225,12 +197,6 @@ watch((value) => {if (layout.value !== 'default') return;- if (position.value.includes('bottom')) {- resetBottom();- } else {- resetTop();- }-if (value) {// calculate the new positionsexpanded.value = true;@@ -239,13 +205,8 @@ watch(}expanded.value = false;- // setTimeout(function () {- // This can get called a bunch of times but since the timer is so short, it will probably be called before the event happens again+ // this used to get call after 10 ms and then again after 10 ms but idk if that is needed anymorestackToasts('HOVER CLOSE');- // }, 10);- // window.setTimeout(function () {- // stackToasts('POST HOVER CLOSE');- // }, 10);},);diff --git a/resources/js/components/pinesUI/ToastNotification.vue b/resources/js/components/pinesUI/ToastNotification.vueindex 0194db56..60059e56 100755--- a/resources/js/components/pinesUI/ToastNotification.vue+++ b/resources/js/components/pinesUI/ToastNotification.vue@@ -3,11 +3,11 @@ import type { SwipeDirection, ToastProps } from '@/types/pinesTypes';import { computed, onBeforeUnmount, onMounted, ref } from 'vue';import { SWIPE_THRESHOLD, TOAST_LIFE } from '@/service/toaster/constants';-import { useToastTimer } from '@/composables/useToastTimer';import { useSwipeHandler } from '@/composables/useSwipeHandler';+import { useToastTimer } from '@/composables/useToastTimer';const emit = defineEmits<{- (e: 'close', id: string): () => void; // removeToast+ (e: 'close', id: string): void; // removeToast}>();const props = withDefaults(defineProps<ToastProps>(), {@@ -42,6 +42,10 @@ const swipeDirections = computed(() => {return directions;});+const isBottom = computed(() => {+ return props.position.includes('bottom');+});+const closeTimeout = ref<null | number>(null);const stackTimeout = ref<null | number>(null);@@ -62,7 +66,7 @@ function getLeaveDirection() {}if (props.toastCount === 1) {- return props.position.includes('bottom') ? 'translate-y-full' : '-translate-y-full';+ return isBottom.value ? 'translate-y-full' : '-translate-y-full';}return 'translate-y-0';@@ -111,13 +115,16 @@ onBeforeUnmount(() => {<template><li+ ref="toastEl":id="props.id"- :class="`toast w-full absolute duration-300 transition-all ease-out ${!description ? 'toast-no-description' : ''} ${style}`"+ :class="[`toast w-full absolute duration-300 transition-all ease-out ${!description ? 'toast-no-description' : ''}`, style]":style="{'--offset-x': `${offset.x}px`,'--offset-y': `${offsetY}px`,'--scale': scale,'--z-index': zIndex,+ '--position-top': `${expanded ? (isBottom ? 'auto' : positionY) : 'inherit'}`,+ '--position-bottom': `${isBottom && expanded ? positionY : 'inherit'}`,}":data-isSwiping="isSwiping"@mouseover="toastHovered = true"@@ -126,10 +133,11 @@ onBeforeUnmount(() => {@pointerdown="onPointerDown"@pointermove="onPointerMove"@pointerup="onPointerUp"+ role="alert"><Transitionenter-active-class=""- :enter-from-class="`opacity-0 ${props.position.includes('bottom') ? 'translate-y-full' : '-translate-y-full'}`"+ :enter-from-class="`opacity-0 ${isBottom ? 'translate-y-full' : '-translate-y-full'}`":enter-to-class="`opacity-100 translate-y-0`"leave-active-class="":leave-from-class="`opacity-100 translate-y-0`"@@ -146,7 +154,6 @@ onBeforeUnmount(() => {'!outline-none focus:ring-gray-400 dark:focus:ring-indigo-500 focus:ring-2',]"v-show="isMounted"- tabindex="0"><divv-if="!props.html"@@ -198,7 +205,7 @@ onBeforeUnmount(() => {:class="{ 'pl-5': props.type !== 'default' }"class="mt-1.5 text-xs leading-tight opacity-70 w-full whitespace-pre-wrap break-words overflow-y-auto scrollbar-minimal max-h-32 min-h-3 pe-2">- {{ props.index }}+ {{ description }}</p><template v-if="!props.html"><span@@ -228,6 +235,8 @@ onBeforeUnmount(() => {.toast {transform: translateY(var(--offset-y, 0px)) translateX(var(--offset-x, 0px)) scale(var(--scale, 1));z-index: var(--z-index, 200);+ top: var(--position-top, inherit);+ bottom: var(--position-bottom, inherit);}@media (prefers-reduced-motion: reduce) {diff --git a/resources/js/composables/useSwipeHandler.ts b/resources/js/composables/useSwipeHandler.tsindex 6e0f80ad..dd95d05c 100644--- a/resources/js/composables/useSwipeHandler.ts+++ b/resources/js/composables/useSwipeHandler.ts@@ -58,7 +58,7 @@ export function useSwipeHandler({ directions, threshold, onSwipeOut }: UseSwipeHfunction onPointerUp() {if (!isSwiping.value) return;- const timeTaken = Date.now() - (dragStartTime.value || 0);+ const timeTaken = Date.now() - (dragStartTime.value ?? 0);const swipeAmount = offset.value.x;const velocity = Math.abs(swipeAmount) / timeTaken;diff --git a/resources/js/views/ProfileView.vue b/resources/js/views/ProfileView.vueindex 34ca2996..af5321cc 100755--- a/resources/js/views/ProfileView.vue+++ b/resources/js/views/ProfileView.vue@@ -45,7 +45,7 @@ Stats: 12 items watched | 9 hours total`</p></div><div class="h-6 flex gap-2 text-sm">- <ButtonText text="Add Friend" @click="toast.error('Friend not added...', { description: 'You do not know why...' })" />+ <ButtonText text="Add Friend" @click="toast.error('Friend not added...', { description: 'You do not know why...', life: 30000, position: 'top-right' })" /><ButtonText text="Block" /></div></section>