-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into file-associations-tauri
- Loading branch information
Showing
11 changed files
with
107 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/components/GlobalErrorBoundary/GlobalErrorBoundary.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Components helpers | ||
*/ | ||
|
||
import * as logger from '@tauri-apps/plugin-log'; | ||
import { isRouteErrorResponse, useRouteError } from 'react-router-dom'; | ||
import ExternalLink from '../../elements/ExternalLink/ExternalLink'; | ||
import * as ViewMessage from '../../elements/ViewMessage/ViewMessage'; | ||
|
||
export default function GlobalErrorBoundary() { | ||
const error = useRouteError(); | ||
let errorMessage: string; | ||
|
||
if (isRouteErrorResponse(error)) { | ||
errorMessage = error.statusText; | ||
} else if (error instanceof Error) { | ||
errorMessage = error.message; | ||
} else if (typeof error === 'string') { | ||
errorMessage = error; | ||
} else { | ||
errorMessage = 'Unknown error'; | ||
} | ||
|
||
logger.error(errorMessage); | ||
|
||
return ( | ||
<ViewMessage.Notice> | ||
<p> | ||
{/* biome-ignore lint/a11y/useSemanticElements: no <img> for emojis */} | ||
<span role="img" aria-label="boom"> | ||
💥 | ||
</span>{' '} | ||
Something wrong happened: {errorMessage} | ||
</p> | ||
<ViewMessage.Sub> | ||
If it happens again, please{' '} | ||
<ExternalLink href="https://github.com/martpie/museeks/issues"> | ||
report an issue | ||
</ExternalLink> | ||
</ViewMessage.Sub> | ||
</ViewMessage.Notice> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import debounce from 'lodash/debounce'; | ||
import { useEffect } from 'react'; | ||
import { useLocation, useNavigation } from 'react-router-dom'; | ||
|
||
function getScrollPosition(key: string) { | ||
const pos = window.sessionStorage.getItem(key); | ||
return Number(pos) || 0; | ||
} | ||
|
||
const setScrollPosition = debounce(function setScrollPosition( | ||
key: string, | ||
pos: number, | ||
) { | ||
window.sessionStorage.setItem(key, pos.toString()); | ||
}, 100); | ||
|
||
/** | ||
* Given a ref to a scrolling container element, keep track of its scroll | ||
* position before navigation and restore it on return (e.g., back/forward nav). | ||
* | ||
* Inspired by: | ||
* https://github.com/remix-run/react-router/pull/10468#issuecomment-1877312374 | ||
* | ||
* Except we want to use location.pathname, and not location.key | ||
*/ | ||
export function useScrollRestoration(container: React.RefObject<HTMLElement>) { | ||
const key = `scroll-position-${useLocation().pathname}`; | ||
const { state } = useNavigation(); | ||
const target = container.current; | ||
|
||
useEffect(() => { | ||
function onScroll() { | ||
setScrollPosition(key, target?.scrollTop ?? 0); | ||
} | ||
|
||
target?.addEventListener('scroll', onScroll); | ||
|
||
return () => { | ||
target?.removeEventListener('scroll', onScroll); | ||
}; | ||
}, [target, key]); | ||
|
||
useEffect(() => { | ||
if (state === 'idle') { | ||
target?.scrollTo(0, getScrollPosition(key)); | ||
} | ||
}, [key, state, target]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters