From 33acfe5b338e45160bed3b35d6986821817ab3d3 Mon Sep 17 00:00:00 2001 From: Rajnish2105 <166371359+Rajnish2105@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:56:46 +0530 Subject: [PATCH 1/3] fixed Browser tab crashes when selecting a high number of room cards in the Explore community tab --- src/app/pages/client/explore/LimitWarning.tsx | 140 ++++++++++++++++++ src/app/pages/client/explore/Server.tsx | 7 +- 2 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 src/app/pages/client/explore/LimitWarning.tsx diff --git a/src/app/pages/client/explore/LimitWarning.tsx b/src/app/pages/client/explore/LimitWarning.tsx new file mode 100644 index 0000000000..78891c03b9 --- /dev/null +++ b/src/app/pages/client/explore/LimitWarning.tsx @@ -0,0 +1,140 @@ +import React, { FormEventHandler, useState } from 'react'; +import FocusTrap from 'focus-trap-react'; +import { + Box, + Button, + Dialog, + Header, + Icon, + IconButton, + Icons, + Input, + Overlay, + OverlayBackdrop, + OverlayCenter, + Text, + config, +} from 'folds'; +import { stopPropagation } from '../../../utils/keyboard'; + +type RectCords = { + x: number; + y: number; + width: number; + height: number; +}; + +type LimitButtonProps = { + limit: number; + onLimitChange: (limit: string) => void; + setMenuAnchor: React.Dispatch>; +}; + +export function LimitWarning({ limit, onLimitChange, setMenuAnchor }: LimitButtonProps) { + const [dialog, setDialog] = useState(false); + const [xlimit, setXLimit] = useState(limit); + + const checklimit: FormEventHandler = (evt) => { + evt.preventDefault(); + const limitInput = evt.currentTarget.limitInput as HTMLInputElement; + if (!limitInput) return; + const newLimit = limitInput.value.trim(); + if (!newLimit) return; + if (parseInt(newLimit, 10) > 9999) { + setDialog(true); + setXLimit(Number(newLimit)); + } else { + onLimitChange(newLimit); + setMenuAnchor(undefined); + } + }; + + const handleLimitSubmit: FormEventHandler = (evt) => { + evt.preventDefault(); + onLimitChange(xlimit.toString()); + setDialog(false); + setMenuAnchor(undefined); + }; + + return ( + <> + }> + + setDialog(false), + escapeDeactivates: stopPropagation, + }} + > + +
+ + Warning!! + + setDialog(false)} radii="300"> + + +
+ + + You are about to change the limit of items per page. Changing the limit higher + than 9,999 may cause performance issues and may crash the app. It is recommended + to keep the limit below 9,999 for the smooth functioning of the app. Are you sure + you want to continue? + + + + + + +
+
+
+
+ + + Custom Limit + + + + + + ); +} diff --git a/src/app/pages/client/explore/Server.tsx b/src/app/pages/client/explore/Server.tsx index 1f493df17f..b5528367df 100644 --- a/src/app/pages/client/explore/Server.tsx +++ b/src/app/pages/client/explore/Server.tsx @@ -45,6 +45,7 @@ import { getMxIdServer } from '../../../utils/matrix'; import { stopPropagation } from '../../../utils/keyboard'; import { ScreenSize, useScreenSizeContext } from '../../../hooks/useScreenSize'; import { BackRouteHandler } from '../../../components/BackRouteHandler'; +import { LimitWarning } from './LimitWarning'; const useServerSearchParams = (searchParams: URLSearchParams): ExploreServerPathSearchParams => useMemo( @@ -260,6 +261,7 @@ function LimitButton({ limit, onLimitChange }: LimitButtonProps) { if (!limitInput) return; const newLimit = limitInput.value.trim(); if (!newLimit) return; + // my work here onLimitChange(newLimit); }; @@ -301,7 +303,8 @@ function LimitButton({ limit, onLimitChange }: LimitButtonProps) { - + + {/* Custom Limit Change Limit - + */} From 2ba196b68c9f1492f77d48bc42a81651622a33b4 Mon Sep 17 00:00:00 2001 From: Rajnish2105 <166371359+Rajnish2105@users.noreply.github.com> Date: Sun, 22 Dec 2024 13:06:22 +0530 Subject: [PATCH 2/3] Dialog made more informative --- src/app/pages/client/explore/LimitWarning.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/pages/client/explore/LimitWarning.tsx b/src/app/pages/client/explore/LimitWarning.tsx index 78891c03b9..27bce62f3b 100644 --- a/src/app/pages/client/explore/LimitWarning.tsx +++ b/src/app/pages/client/explore/LimitWarning.tsx @@ -92,10 +92,10 @@ export function LimitWarning({ limit, onLimitChange, setMenuAnchor }: LimitButto gap="400" > - You are about to change the limit of items per page. Changing the limit higher - than 9,999 may cause performance issues and may crash the app. It is recommended - to keep the limit below 9,999 for the smooth functioning of the app. Are you sure - you want to continue? + You are about to change the limit of items. Changing the limit higher than 9,999 + may cause performance issues and may crash the app. It is recommended to keep the + limit below 9,999 for the smooth functioning of the app. Are you sure you want to + continue? - - - - - - - - - - Custom Limit - - - - - - ); -} diff --git a/src/app/pages/client/explore/Server.tsx b/src/app/pages/client/explore/Server.tsx index b5528367df..c757dd79b3 100644 --- a/src/app/pages/client/explore/Server.tsx +++ b/src/app/pages/client/explore/Server.tsx @@ -45,7 +45,7 @@ import { getMxIdServer } from '../../../utils/matrix'; import { stopPropagation } from '../../../utils/keyboard'; import { ScreenSize, useScreenSizeContext } from '../../../hooks/useScreenSize'; import { BackRouteHandler } from '../../../components/BackRouteHandler'; -import { LimitWarning } from './LimitWarning'; +// import { LimitWarning } from './LimitWarning'; const useServerSearchParams = (searchParams: URLSearchParams): ExploreServerPathSearchParams => useMemo( @@ -301,18 +301,27 @@ function LimitButton({ limit, onLimitChange }: LimitButtonProps) { setLimit('96')} radii="Pill"> 96 + setLimit('10000')} radii="Pill"> + Max + - - {/* + Custom Limit ) => { + if (parseInt(e.target.value) > 10000) { + e.target.value = e.target.value.slice(0, 4); + } + }} step={1} outlined type="number" @@ -323,7 +332,7 @@ function LimitButton({ limit, onLimitChange }: LimitButtonProps) { - */} +