Skip to content

A self-hosted media server and file management system

fix: visible toasts are deleted as overflow even if they should stay visible

aminnausin352d8c737638
diff --git a/resources/js/components/pinesUI/ToastController.vue b/resources/js/components/pinesUI/ToastController.vue
index 5eb6343b..8cb62717 100755
--- a/resources/js/components/pinesUI/ToastController.vue
+++ b/resources/js/components/pinesUI/ToastController.vue
@@ -97,34 +97,7 @@ function positionToasts(_?: any) {
}
}
- handleToastsOverflow(toastElements);
- } catch (error) {
- console.log(error);
- }
-}
-
-function handleToastsOverflow(toastElements: HTMLElement[]) {
- if (messages.value.length <= props.maxVisibleToasts) {
- return;
- }
-
- try {
- const burnToast = document.getElementById(`${messages.value[props.maxVisibleToasts]?.id}`);
-
- if (!burnToast) {
- return;
- }
-
- burnToast.firstElementChild?.classList.add('opacity-0');
-
- // Burn 🔥 (remove) last toast
- burnTimeout.value = window.setTimeout(function () {
- messages.value.pop();
- }, 300);
-
- if (position.value.includes('bottom')) {
- toastElements[1].style.top = 'auto';
- }
+ // Don't handle overflow anymore. All toasts must adhere to their lifecycle and dismissing a newer toast will reveal an older one
} catch (error) {
console.log(error);
}
@@ -138,7 +111,7 @@ function calculateHeightOfToastsContainer() {
return;
}
- const lastToast = messages.value[messages.value.length - 1];
+ const lastToast = messages.value[Math.max(Math.min(messages.value.length - 1, props.maxVisibleToasts - 1), 0)];
const lastToastRectangle = document.getElementById(`${lastToast?.id}`)?.getBoundingClientRect();
const firstToast = messages.value[0];
@@ -280,6 +253,7 @@ watchEffect((onInvalidate) => {
:position="position"
:expanded="expanded"
:index="index"
+ :maxVisibleToasts="maxVisibleToasts"
@close="deleteToastWithId"
/>
</ol>
diff --git a/resources/js/components/pinesUI/ToastNotification.vue b/resources/js/components/pinesUI/ToastNotification.vue
index 06b7f650..50400326 100755
--- a/resources/js/components/pinesUI/ToastNotification.vue
+++ b/resources/js/components/pinesUI/ToastNotification.vue
@@ -1,8 +1,8 @@
<script setup lang="ts">
import type { SwipeDirection, ToastProps } from '@/types/pinesTypes';
+import { SWIPE_THRESHOLD, TOAST_LIFE, VISIBLE_TOASTS_AMOUNT } from '@/service/toaster/constants';
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
-import { SWIPE_THRESHOLD, TOAST_LIFE } from '@/service/toaster/constants';
import { useSwipeHandler } from '@/composables/useSwipeHandler';
import { useToastTimer } from '@/composables/useToastTimer';
@@ -12,6 +12,7 @@ const props = withDefaults(defineProps<ToastProps>(), {
type: 'default',
position: 'bottom-center',
life: TOAST_LIFE,
+ maxVisibleToasts: VISIBLE_TOASTS_AMOUNT,
title: 'Title',
html: '',
style: '',
@@ -115,7 +116,12 @@ onBeforeUnmount(() => {
<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`,
+ { 'toast-no-description': !description },
+ { 'opacity-0 pointer-events-none': index >= maxVisibleToasts },
+ style,
+ ]"
:style="{
'--offset-x': `${offset.x}px`,
'--offset-y': `${offsetY}px`,
diff --git a/resources/js/types/pinesTypes.ts b/resources/js/types/pinesTypes.ts
index 58e9307a..0faf3fcd 100644
--- a/resources/js/types/pinesTypes.ts
+++ b/resources/js/types/pinesTypes.ts
@@ -27,13 +27,14 @@ export interface ToastControllerProps {
export interface ToastProps extends Message {
id: string;
+ index: number;
stack: (...args: unknown[]) => unknown;
position: ToastPostion;
toastCount: number;
expanded: boolean;
+ maxVisibleToasts?: number;
swipeDirections?: SwipeDirection[];
style?: string;
- index?: number;
}
export type SwipeDirection = 'top' | 'right' | 'bottom' | 'left';
diff --git a/resources/js/views/ProfileView.vue b/resources/js/views/ProfileView.vue
index af5321cc..5d01531e 100755
--- a/resources/js/views/ProfileView.vue
+++ b/resources/js/views/ProfileView.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
-import { useAppStore } from '../stores/AppStore';
+import { onMounted, ref } from 'vue';
+import { useAppStore } from '@/stores/AppStore';
import { storeToRefs } from 'pinia';
-import { onMounted } from 'vue';
import { toast } from '@/service/toaster/toastService';
import ProfileHeader from '@/components/profile/ProfileHeader.vue';
@@ -10,6 +10,8 @@ import LayoutBase from '@/layouts/LayoutBase.vue';
const { pageTitle, selectedSideBar } = storeToRefs(useAppStore());
+const blockedFriends = ref(0);
+
onMounted(() => {
pageTitle.value = 'User Profile';
selectedSideBar.value = '';
@@ -43,10 +45,19 @@ Socials:
Stats: 12 items watched | 9 hours total`
}}
</p>
+ <p class="text-xs mt-16">This page is a work in progress if it wasn't obvious</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...', life: 30000, position: 'top-right' })" />
- <ButtonText text="Block" />
+ <ButtonText text="Add Friend" @click="toast.error('Friend not added...', { description: 'You do not know why...' })" />
+ <ButtonText
+ text="Block"
+ @click="
+ () => {
+ blockedFriends += 1;
+ toast.info('Friend Blocked', { description: `You have blocked ${blockedFriends} friends. How nice of you.` });
+ }
+ "
+ />
</div>
</section>
</section>