Skip to content

Commit

Permalink
Merge branch 'master' into file-associations-tauri
Browse files Browse the repository at this point in the history
  • Loading branch information
martpie authored Sep 20, 2024
2 parents 6ef76e3 + 546489e commit 76bf5c3
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 98 deletions.
11 changes: 10 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"linter": {
"enabled": true,
"rules": {
Expand All @@ -9,6 +9,9 @@
},
"suspicious": {
"noImplicitAnyLet": "off"
},
"nursery": {
"useComponentExportOnlyModules": "warn"
}
}
},
Expand All @@ -25,6 +28,12 @@
"css": {
"parser": {
"cssModules": true
},
"linter": {
"enabled": true
},
"formatter": {
"enabled": true
}
},
"files": {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"zustand": "^4.5.5"
},
"devDependencies": {
"@biomejs/biome": "1.9.1",
"@biomejs/biome": "1.9.2",
"@tauri-apps/cli": "2.0.0-rc.12",
"@types/bun": "^1.1.9",
"@types/lodash": "^4.17.7",
Expand Down
43 changes: 43 additions & 0 deletions src/components/GlobalErrorBoundary/GlobalErrorBoundary.tsx
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>
);
}
2 changes: 2 additions & 0 deletions src/components/TracksList/TracksList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { usePlayerAPI } from '../../stores/usePlayerStore';
import TrackRow from '../TrackRow/TrackRow';
import TracksListHeader from '../TracksListHeader/TracksListHeader';

import { useScrollRestoration } from '../../hooks/useScrollRestoration';
import styles from './TracksList.module.css';

const ROW_HEIGHT = 30;
Expand Down Expand Up @@ -87,6 +88,7 @@ export default function TracksList(props: Props) {
const playerAPI = usePlayerAPI();
const libraryAPI = useLibraryAPI();
const highlight = useLibraryStore((state) => state.highlightPlayingTrack);
useScrollRestoration(scrollableRef);

// Highlight playing track and scroll to it
// Super-mega-hacky to use Redux for that
Expand Down
26 changes: 0 additions & 26 deletions src/hooks/useDebounce.ts

This file was deleted.

48 changes: 48 additions & 0 deletions src/hooks/useScrollRestoration.ts
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]);
}
1 change: 0 additions & 1 deletion src/stores/SettingsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ async function toggleLibraryAutorefresh(value: boolean): Promise<void> {
async function checkForLibraryRefresh(): Promise<void> {
const autorefreshEnabled = await config.getInitial('library_autorefresh');

console.log('autorefresh', autorefreshEnabled);
if (autorefreshEnabled) {
useLibraryStore.getState().api.refresh();
}
Expand Down
15 changes: 0 additions & 15 deletions src/types/museeks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Track } from '../generated/typings';

/**
* Player related stuff
*/
Expand All @@ -9,19 +7,6 @@ export enum PlayerStatus {
STOP = 'stop',
}

/**
* Editable track fields (via right-click -> edit track)
*/
export type TrackEditableFields = Pick<
Track,
'title' | 'artists' | 'album' | 'genres'
>;

export type TrackSearchableFields = Pick<
Track,
'title' | 'artists' | 'album' | 'genres'
>;

/**
* Various
*/
Expand Down
6 changes: 1 addition & 5 deletions src/views/ViewSettingsLibrary.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
border: solid 1px var(--border-color);
overflow-x: auto;
white-space: pre;
width: 150%;
/* overflow-x: auto;
white-space: nowrap; */
/* overflow: hidden; */
/* white-space: pre; */
width: 120%;
}

.libraryFoldersRemove {
Expand Down
51 changes: 2 additions & 49 deletions src/views/router.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import * as logger from '@tauri-apps/plugin-log';
import {
type LoaderFunctionArgs,
createHashRouter,
isRouteErrorResponse,
useRouteError,
} from 'react-router-dom';

import ExternalLink from '../elements/ExternalLink/ExternalLink';
import * as ViewMessage from '../elements/ViewMessage/ViewMessage';
import { type LoaderFunctionArgs, createHashRouter } from 'react-router-dom';

import GlobalErrorBoundary from '../components/GlobalErrorBoundary/GlobalErrorBoundary';
import RootView from './Root';
import ViewLibrary from './ViewLibrary';
import ViewPlaylistDetails from './ViewPlaylistDetails';
Expand Down Expand Up @@ -86,45 +78,6 @@ const router = createHashRouter([

export default router;

/**
* Components helpers
*/

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>
);
}

/**
* Loader Types, to manually type useLoaderData()
*/
Expand Down

0 comments on commit 76bf5c3

Please sign in to comment.