Browse Source

Improve multiselect dragging

- Use range selection instead of appending individual entries
master
jeffvli 3 years ago
parent
commit
a4c9feeb7c
  1. 8
      src/components/layout/Layout.tsx
  2. 11
      src/components/library/AlbumList.tsx
  3. 8
      src/components/library/AlbumView.tsx
  4. 8
      src/components/library/ArtistView.tsx
  5. 3
      src/components/player/NowPlayingMiniView.tsx
  6. 3
      src/components/player/NowPlayingView.tsx
  7. 3
      src/components/playlist/PlaylistView.tsx
  8. 16
      src/components/starred/StarredView.tsx
  9. 102
      src/components/viewtypes/ListViewTable.tsx

8
src/components/layout/Layout.tsx

@ -6,11 +6,13 @@ import Titlebar from './Titlebar';
import { RootContainer, RootFooter, MainContainer } from './styled'; import { RootContainer, RootFooter, MainContainer } from './styled';
import { setContextMenu, setExpandSidebar } from '../../redux/miscSlice'; import { setContextMenu, setExpandSidebar } from '../../redux/miscSlice';
import { useAppDispatch, useAppSelector } from '../../redux/hooks'; import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { clearSelected } from '../../redux/multiSelectSlice';
const Layout = ({ footer, children, disableSidebar, font }: any) => { const Layout = ({ footer, children, disableSidebar, font }: any) => {
const history = useHistory(); const history = useHistory();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const misc = useAppSelector((state) => state.misc); const misc = useAppSelector((state) => state.misc);
const multiSelect = useAppSelector((state) => state.multiSelect);
const handleToggle = () => { const handleToggle = () => {
dispatch(setExpandSidebar(!misc.expandSidebar)); dispatch(setExpandSidebar(!misc.expandSidebar));
@ -72,6 +74,12 @@ const Layout = ({ footer, children, disableSidebar, font }: any) => {
}) })
); );
} }
if (
multiSelect.selected.length > 0 &&
!multiSelect.isSelectDragging
) {
dispatch(clearSelected());
}
}} }}
/> />
<RootContainer <RootContainer

11
src/components/library/AlbumList.tsx

@ -13,7 +13,6 @@ import {
toggleSelected, toggleSelected,
setRangeSelected, setRangeSelected,
toggleRangeSelected, toggleRangeSelected,
setSelected,
} from '../../redux/multiSelectSlice'; } from '../../redux/multiSelectSlice';
import { StyledInputPicker } from '../shared/styled'; import { StyledInputPicker } from '../shared/styled';
@ -55,13 +54,9 @@ const AlbumList = () => {
dispatch(toggleSelected(rowData)); dispatch(toggleSelected(rowData));
} else if (e.shiftKey) { } else if (e.shiftKey) {
dispatch(setRangeSelected(rowData)); dispatch(setRangeSelected(rowData));
if (searchQuery !== '') { dispatch(
dispatch(toggleRangeSelected(filteredData)); toggleRangeSelected(searchQuery !== '' ? filteredData : albums)
} else { );
dispatch(toggleRangeSelected(albums));
}
} else {
dispatch(setSelected(rowData));
} }
}, 100); }, 100);
} }

8
src/components/library/AlbumView.tsx

@ -20,7 +20,6 @@ import {
toggleSelected, toggleSelected,
setRangeSelected, setRangeSelected,
toggleRangeSelected, toggleRangeSelected,
setSelected,
clearSelected, clearSelected,
} from '../../redux/multiSelectSlice'; } from '../../redux/multiSelectSlice';
import useSearchQuery from '../../hooks/useSearchQuery'; import useSearchQuery from '../../hooks/useSearchQuery';
@ -67,10 +66,9 @@ const AlbumView = ({ ...rest }: any) => {
dispatch(toggleSelected(rowData)); dispatch(toggleSelected(rowData));
} else if (e.shiftKey) { } else if (e.shiftKey) {
dispatch(setRangeSelected(rowData)); dispatch(setRangeSelected(rowData));
dispatch(
dispatch(toggleRangeSelected(data.song)); toggleRangeSelected(searchQuery !== '' ? filteredData : data.song)
} else { );
dispatch(setSelected(rowData));
} }
}, 100); }, 100);
} }

8
src/components/library/ArtistView.tsx

@ -15,7 +15,6 @@ import {
toggleSelected, toggleSelected,
setRangeSelected, setRangeSelected,
toggleRangeSelected, toggleRangeSelected,
setSelected,
clearSelected, clearSelected,
} from '../../redux/multiSelectSlice'; } from '../../redux/multiSelectSlice';
import useSearchQuery from '../../hooks/useSearchQuery'; import useSearchQuery from '../../hooks/useSearchQuery';
@ -70,10 +69,9 @@ const ArtistView = ({ ...rest }: any) => {
dispatch(toggleSelected(rowData)); dispatch(toggleSelected(rowData));
} else if (e.shiftKey) { } else if (e.shiftKey) {
dispatch(setRangeSelected(rowData)); dispatch(setRangeSelected(rowData));
dispatch(
dispatch(toggleRangeSelected(data.album)); toggleRangeSelected(searchQuery !== '' ? filteredData : data.album)
} else { );
dispatch(setSelected(rowData));
} }
}, 100); }, 100);
} }

3
src/components/player/NowPlayingMiniView.tsx

@ -6,7 +6,6 @@ import {
toggleSelected, toggleSelected,
setRangeSelected, setRangeSelected,
toggleRangeSelected, toggleRangeSelected,
setSelected,
clearSelected, clearSelected,
setIsDragging, setIsDragging,
} from '../../redux/multiSelectSlice'; } from '../../redux/multiSelectSlice';
@ -77,8 +76,6 @@ const NowPlayingMiniView = () => {
: playQueue.entry : playQueue.entry
) )
); );
} else {
dispatch(setSelected(rowData));
} }
}, 100); }, 100);
} }

3
src/components/player/NowPlayingView.tsx

@ -19,7 +19,6 @@ import {
toggleSelected, toggleSelected,
setRangeSelected, setRangeSelected,
toggleRangeSelected, toggleRangeSelected,
setSelected,
clearSelected, clearSelected,
setIsDragging, setIsDragging,
} from '../../redux/multiSelectSlice'; } from '../../redux/multiSelectSlice';
@ -80,8 +79,6 @@ const NowPlayingView = () => {
) )
); );
} }
} else {
dispatch(setSelected(rowData));
} }
}, 100); }, 100);
} }

3
src/components/playlist/PlaylistView.tsx

@ -32,7 +32,6 @@ import {
toggleSelected, toggleSelected,
setRangeSelected, setRangeSelected,
toggleRangeSelected, toggleRangeSelected,
setSelected,
clearSelected, clearSelected,
setIsDragging, setIsDragging,
} from '../../redux/multiSelectSlice'; } from '../../redux/multiSelectSlice';
@ -135,8 +134,6 @@ const PlaylistView = ({ ...rest }) => {
searchQuery !== '' ? filteredData : localPlaylistData searchQuery !== '' ? filteredData : localPlaylistData
) )
); );
} else {
dispatch(setSelected(rowData));
} }
}, 100); }, 100);
} }

16
src/components/starred/StarredView.tsx

@ -11,7 +11,6 @@ import {
} from '../../redux/playQueueSlice'; } from '../../redux/playQueueSlice';
import { import {
clearSelected, clearSelected,
setSelected,
toggleSelected, toggleSelected,
toggleRangeSelected, toggleRangeSelected,
setRangeSelected, setRangeSelected,
@ -65,17 +64,12 @@ const StarredView = () => {
} }
} else if (currentPage === 'Albums') { } else if (currentPage === 'Albums') {
dispatch(setRangeSelected(rowData)); dispatch(setRangeSelected(rowData));
if (searchQuery !== '') { dispatch(
dispatch(toggleRangeSelected(filteredData)); toggleRangeSelected(
} else { searchQuery !== '' ? filteredData : data?.album
dispatch(toggleRangeSelected(data?.album)); )
} );
} else {
// !TODO
data.song.slice();
} }
} else {
dispatch(setSelected(rowData));
} }
}, 100); }, 100);
} }

102
src/components/viewtypes/ListViewTable.tsx

@ -34,11 +34,14 @@ import {
import { StyledIconToggle, StyledRate } from '../shared/styled'; import { StyledIconToggle, StyledRate } from '../shared/styled';
import { addModalPage, setContextMenu } from '../../redux/miscSlice'; import { addModalPage, setContextMenu } from '../../redux/miscSlice';
import { import {
appendSelected, clearSelected,
setCurrentMouseOverId, setCurrentMouseOverId,
setIsDragging, setIsDragging,
setIsSelectDragging, setIsSelectDragging,
setRangeSelected,
setSelectedSingle, setSelectedSingle,
toggleRangeSelected,
toggleSelected,
} from '../../redux/multiSelectSlice'; } from '../../redux/multiSelectSlice';
const ListViewTable = ({ const ListViewTable = ({
@ -134,6 +137,46 @@ const ListViewTable = ({
} }
}; };
// Acts as our initial multiSelect handler by toggling the selected row
// and continuing the selection drag if the mouse button is held down
const handleSelectMouseDown = (e: any, rowData: any) => {
// If ctrl or shift is used, we want to ignore this drag selection handler
// and use the ones provided in handleRowClick
if (e.button === 0 && !e.ctrlKey && !e.shiftKey) {
if (
multiSelect.selected.length === 1 &&
multiSelect.selected[0].uniqueId === rowData.uniqueId
) {
// Toggle single entry if the same entry is clicked
dispatch(clearSelected());
} else {
if (multiSelect.selected.length > 0) {
dispatch(clearSelected());
}
dispatch(setIsSelectDragging(true));
dispatch(toggleSelected(rowData));
}
}
};
// Completes the multiSelect handler once the mouse button is lifted
const handleSelectMouseUp = () => {
dispatch(setIsDragging(false));
dispatch(setIsSelectDragging(false));
};
// If mouse is still held down from the handleSelectMouseDown function, then
// mousing over a row will set the range selection from the initial mousedown location
// to the mouse-entered row
const handleSelectMouseEnter = (rowData: any) => {
if (multiSelect.isSelectDragging) {
dispatch(setRangeSelected(rowData));
dispatch(
toggleRangeSelected(sortColumn && !nowPlaying ? sortedData : data)
);
}
};
useEffect(() => { useEffect(() => {
if (!nowPlaying) { if (!nowPlaying) {
if (sortColumn && sortType) { if (sortColumn && sortType) {
@ -418,20 +461,11 @@ const ListViewTable = ({
rowIndex, rowIndex,
}) })
} }
onMouseDown={(e: any) => { onMouseDown={(e: any) =>
if (e.button === 0) { handleSelectMouseDown(e, rowData)
dispatch(setIsSelectDragging(true)); }
} onMouseEnter={() => handleSelectMouseEnter(rowData)}
}} onMouseUp={() => handleSelectMouseUp()}
onMouseOver={() => {
if (multiSelect.isSelectDragging) {
dispatch(appendSelected(rowData));
}
}}
onMouseUp={() => {
dispatch(setIsDragging(false));
dispatch(setIsSelectDragging(false));
}}
dragover={ dragover={
multiSelect.currentMouseOverId === rowData.uniqueId && multiSelect.currentMouseOverId === rowData.uniqueId &&
multiSelect.isDragging multiSelect.isDragging
@ -595,20 +629,11 @@ const ListViewTable = ({
: 'false' : 'false'
} }
height={rowHeight} height={rowHeight}
onMouseDown={(e: any) => { onMouseDown={(e: any) =>
if (e.button === 0) { handleSelectMouseDown(e, rowData)
dispatch(setIsSelectDragging(true)); }
} onMouseEnter={() => handleSelectMouseEnter(rowData)}
}} onMouseUp={() => handleSelectMouseUp()}
onMouseOver={() => {
if (multiSelect.isSelectDragging) {
dispatch(appendSelected(rowData));
}
}}
onMouseUp={() => {
dispatch(setIsDragging(false));
dispatch(setIsSelectDragging(false));
}}
dragover={ dragover={
multiSelect.currentMouseOverId === rowData.uniqueId && multiSelect.currentMouseOverId === rowData.uniqueId &&
multiSelect.isDragging multiSelect.isDragging
@ -692,20 +717,11 @@ const ListViewTable = ({
}); });
} }
}} }}
onMouseDown={(e: any) => { onMouseDown={(e: any) =>
if (e.button === 0) { handleSelectMouseDown(e, rowData)
dispatch(setIsSelectDragging(true)); }
} onMouseEnter={() => handleSelectMouseEnter(rowData)}
}} onMouseUp={() => handleSelectMouseUp()}
onMouseOver={() => {
if (multiSelect.isSelectDragging) {
dispatch(appendSelected(rowData));
}
}}
onMouseUp={() => {
dispatch(setIsDragging(false));
dispatch(setIsSelectDragging(false));
}}
dragover={ dragover={
multiSelect.currentMouseOverId === rowData.uniqueId && multiSelect.currentMouseOverId === rowData.uniqueId &&
multiSelect.isDragging multiSelect.isDragging

Loading…
Cancel
Save