Skip to content

Commit

Permalink
feat(playlist): default to unformatted track id copying
Browse files Browse the repository at this point in the history
  • Loading branch information
nanochromatic committed Feb 1, 2024
1 parent 2d5778d commit 7ea8fab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
19 changes: 18 additions & 1 deletion src/components/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ export const SettingsModal: React.FC<ISettingsModalProps> = ({
const [distinctKmstVersion, setDistinctKmstVersion] = useState(
settings.distinctKmstVersion
);
const [jsonOptimizedTrackIdCopy, setJsonOptimizedTrackIdCopy] = useState(
settings.jsonOptimizedTrackIdCopy
);

const onModalSave = () => {
setSettings({ hideMinorTracks, distinctKmstVersion });
setSettings({
hideMinorTracks,
distinctKmstVersion,
jsonOptimizedTrackIdCopy,
});
onModalClose();
};

const onModalShow = () => {
setHideMinorTracks(settings.hideMinorTracks);
setDistinctKmstVersion(settings.distinctKmstVersion);
setJsonOptimizedTrackIdCopy(settings.jsonOptimizedTrackIdCopy);
};

return (
Expand Down Expand Up @@ -64,6 +72,15 @@ export const SettingsModal: React.FC<ISettingsModalProps> = ({
setDistinctKmstVersion((prev) => !prev);
}}
/>
<SettingsModalToggle
id="jsonOptimizedTrackIdCopy"
label="JSON Optimized Track ID Copy"
checked={jsonOptimizedTrackIdCopy}
tooltip="Wrap track ID in JSON compatible syntax"
onChange={() => {
setJsonOptimizedTrackIdCopy((prev) => !prev);
}}
/>
</div>
</>
</Form>
Expand Down
16 changes: 12 additions & 4 deletions src/components/renderers/TrackIdRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/** @jsxImportSource @emotion/react */
import React, { useMemo } from 'react';
import React, { useCallback, useMemo } from 'react';
import { ICellRendererParams } from 'ag-grid-community';
import { css } from '@emotion/react';
import { getKey } from '../utils/PlaylistUtils';
import { OverlayTrigger, Tooltip } from 'react-bootstrap';
import { useAtom } from 'jotai';
import { trackExportSetAtom } from '../../state/playlist';
import { useSettings } from '../../context/SettingsContext';

export const TrackIdRenderer: React.FC<ICellRendererParams> = (params) => {
const { settings } = useSettings();
const { data } = params;
const key = useMemo(() => getKey(data.source.structure, data.filename), [
data.source.structure,
Expand All @@ -19,6 +21,14 @@ export const TrackIdRenderer: React.FC<ICellRendererParams> = (params) => {
trackExportSet,
]);

const onCopyTrackId = useCallback(() => {
if (settings.jsonOptimizedTrackIdCopy) {
navigator.clipboard.writeText(`"${key}",\n`);
} else {
navigator.clipboard.writeText(key);
}
}, [key, settings.jsonOptimizedTrackIdCopy]);

const onExportSetChange = () => {
if (trackInExportSet) {
trackExportSet.delete(key);
Expand All @@ -40,9 +50,7 @@ export const TrackIdRenderer: React.FC<ICellRendererParams> = (params) => {
css={css`
margin: 0 5px;
`}
onClick={() => {
navigator.clipboard.writeText(`"${key}",\n`);
}}
onClick={onCopyTrackId}
>
<OverlayTrigger
delay={{ show: 1000, hide: 100 }}
Expand Down
2 changes: 2 additions & 0 deletions src/context/SettingsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const LOCAL_STORAGE_KEY = 'site-preferences';
interface ISettings {
hideMinorTracks: boolean;
distinctKmstVersion: boolean;
jsonOptimizedTrackIdCopy: boolean;
}

type SettingsContextOutput = {
Expand All @@ -19,6 +20,7 @@ const SettingsContext = React.createContext<SettingsContextOutput | undefined>(
const defaultSettings: ISettings = {
hideMinorTracks: false,
distinctKmstVersion: false,
jsonOptimizedTrackIdCopy: false,
};

function getDefaultSettings(): ISettings {
Expand Down

0 comments on commit 7ea8fab

Please sign in to comment.