From 7ea8fabe04b14a2e47f5560a7d9c163559a76de6 Mon Sep 17 00:00:00 2001 From: Wesley Dai Date: Wed, 31 Jan 2024 21:32:30 -0600 Subject: [PATCH] feat(playlist): default to unformatted track id copying --- src/components/SettingsModal.tsx | 19 ++++++++++++++++++- src/components/renderers/TrackIdRenderer.tsx | 16 ++++++++++++---- src/context/SettingsContext.tsx | 2 ++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/components/SettingsModal.tsx b/src/components/SettingsModal.tsx index 24ebc79..11de151 100644 --- a/src/components/SettingsModal.tsx +++ b/src/components/SettingsModal.tsx @@ -21,15 +21,23 @@ export const SettingsModal: React.FC = ({ 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 ( @@ -64,6 +72,15 @@ export const SettingsModal: React.FC = ({ setDistinctKmstVersion((prev) => !prev); }} /> + { + setJsonOptimizedTrackIdCopy((prev) => !prev); + }} + /> diff --git a/src/components/renderers/TrackIdRenderer.tsx b/src/components/renderers/TrackIdRenderer.tsx index e328844..091e924 100644 --- a/src/components/renderers/TrackIdRenderer.tsx +++ b/src/components/renderers/TrackIdRenderer.tsx @@ -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 = (params) => { + const { settings } = useSettings(); const { data } = params; const key = useMemo(() => getKey(data.source.structure, data.filename), [ data.source.structure, @@ -19,6 +21,14 @@ export const TrackIdRenderer: React.FC = (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); @@ -40,9 +50,7 @@ export const TrackIdRenderer: React.FC = (params) => { css={css` margin: 0 5px; `} - onClick={() => { - navigator.clipboard.writeText(`"${key}",\n`); - }} + onClick={onCopyTrackId} > ( const defaultSettings: ISettings = { hideMinorTracks: false, distinctKmstVersion: false, + jsonOptimizedTrackIdCopy: false, }; function getDefaultSettings(): ISettings {