diff --git a/lib/src/Components/Map/Subcomponents/ItemViewPopup.tsx b/lib/src/Components/Map/Subcomponents/ItemViewPopup.tsx index fe7e4107..4f623c0c 100644 --- a/lib/src/Components/Map/Subcomponents/ItemViewPopup.tsx +++ b/lib/src/Components/Map/Subcomponents/ItemViewPopup.tsx @@ -5,7 +5,6 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ /* eslint-disable @typescript-eslint/prefer-optional-chain */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { LatLng } from 'leaflet' import { forwardRef, useState } from 'react' @@ -17,6 +16,7 @@ import { useRemoveItem, useUpdateItem } from '#components/Map/hooks/useItems' import { usePopupForm } from '#components/Map/hooks/usePopupForm' import { useSetSelectPosition } from '#components/Map/hooks/useSelectPosition' import { timeAgo } from '#utils/TimeAgo' +import { removeItemFromUrl } from '#utils/UrlHelper' import { HeaderView } from './ItemPopupComponents/HeaderView' import { TextView } from './ItemPopupComponents/TextView' @@ -80,8 +80,7 @@ export const ItemViewPopup = forwardRef((props: ItemViewPopupProps, ref: any) => } setLoading(false) map.closePopup() - const params = new URLSearchParams(window.location.search) - window.history.pushState({}, '', '/' + `${params ? `?${params}` : ''}`) + removeItemFromUrl() navigate('/') } diff --git a/lib/src/Components/Profile/Templates/TabsView.tsx b/lib/src/Components/Profile/Templates/TabsView.tsx index 0844f8fa..94806d9d 100644 --- a/lib/src/Components/Profile/Templates/TabsView.tsx +++ b/lib/src/Components/Profile/Templates/TabsView.tsx @@ -17,6 +17,7 @@ import { ActionButton } from '#components/Profile/Subcomponents/ActionsButton' import { LinkedItemsHeaderView } from '#components/Profile/Subcomponents/LinkedItemsHeaderView' import { TagView } from '#components/Templates/TagView' import { timeAgo } from '#utils/TimeAgo' +import { setUrlParam } from '#utils/UrlHelper' import type { Item } from '#types/Item' import type { Tag } from '#types/Tag' @@ -67,11 +68,7 @@ export const TabsView = ({ const updateActiveTab = useCallback( (id: number) => { setActiveTab(id) - - const params = new URLSearchParams(window.location.search) - params.set('tab', `${id}`) - const newUrl = location.pathname + '?' + params.toString() - window.history.pushState({}, '', newUrl) + setUrlParam('tab', `${id}`) }, // eslint-disable-next-line react-hooks/exhaustive-deps [location.pathname], diff --git a/lib/src/Components/Profile/itemFunctions.ts b/lib/src/Components/Profile/itemFunctions.ts index 4c229c8b..b26c7142 100644 --- a/lib/src/Components/Profile/itemFunctions.ts +++ b/lib/src/Components/Profile/itemFunctions.ts @@ -14,6 +14,7 @@ import { toast } from 'react-toastify' import { encodeTag } from '#utils/FormatTags' import { hashTagRegex } from '#utils/HashTagRegex' import { randomColor } from '#utils/RandomColor' +import { removeItemFromUrl } from '#utils/UrlHelper' import type { FormState } from '#types/FormState' import type { Item } from '#types/Item' @@ -185,8 +186,7 @@ export const handleDelete = async ( toast.success('Item deleted') map.closePopup() - const params = new URLSearchParams(window.location.search) - window.history.pushState({}, '', '/' + `${params ? `?${params}` : ''}`) + removeItemFromUrl() navigate('/') } catch (error) { toast.error(error instanceof Error ? error.message : String(error))