pull/3663/head
Mitja Bezenšek 2024-05-03 12:24:16 +02:00
rodzic cf9d8b8cff
commit c0ad593dde
2 zmienionych plików z 1 dodań i 25 usunięć

Wyświetl plik

@ -19,7 +19,6 @@ import {
import { useShareMenuIsOpen } from '../hooks/useShareMenuOpen'
import { createQRCodeImageDataString } from '../utils/qrcode'
import { SHARE_PROJECT_ACTION, SHARE_SNAPSHOT_ACTION } from '../utils/sharing'
import { sameUrls } from '../utils/url'
import { ShareButton } from './ShareButton'
const SHARE_CURRENT_STATE = {
@ -146,7 +145,7 @@ export const ShareMenu = React.memo(function ShareMenu() {
const interval = setInterval(() => {
const url = window.location.href
if (sameUrls(url, shareState.url)) return
if (shareState.url === url) return
setShareState(getFreshShareState())
}, 300)

Wyświetl plik

@ -1,26 +1,3 @@
export function openUrl(url: string) {
window.open(url, '_blank')
}
/**
* Compares two URLs to see if they are the same. This ignores encoding.
* @param first - The first URL to compare.
* @param second - The second URL to compare.
* @returns Whether the URLs are the same.
*/
export function sameUrls(first: string, second: string): boolean {
const firstUrl = new URL(first)
const secondUrl = new URL(second)
const firstPathname = decodeURIComponent(firstUrl.pathname)
const secondPathname = decodeURIComponent(secondUrl.pathname)
const firstSearch = decodeURIComponent(firstUrl.search)
const secondSearch = decodeURIComponent(secondUrl.search)
const firstHash = decodeURIComponent(firstUrl.hash)
const secondHash = decodeURIComponent(secondUrl.hash)
return (
firstUrl.origin === secondUrl.origin &&
firstPathname === secondPathname &&
firstSearch === secondSearch &&
firstHash === secondHash
)
}