Skip to content

Commit

Permalink
Fix range selection by using view hash list (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminpaks committed Feb 2, 2021
1 parent d9da9e2 commit c90360a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/components/state/server-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const initialTorrentSortFilterState: SortFilterStateValue = {
const ServerContext = createContext(initialServerState);
const TorrentsContext = createContext(initialTorrentsState);
const TorrentHashListContext = createContext(initialTorrentsState.hashList);
const TorrentViewHashListContext = createContext(initialTorrentsState.viewHashList);
const TorrentSortFilterContext = createContext(([
initialTorrentSortFilterState,
undefined,
Expand Down Expand Up @@ -238,9 +239,11 @@ export const AppContextProvider: FC = ({ children }) => {
<ServerContext.Provider value={serverState}>
<TorrentsContext.Provider value={torrentsState}>
<TorrentHashListContext.Provider value={torrentsState.hashList}>
<TorrentSortFilterContext.Provider value={[torrentSortFilterState, handleListSortFilter]}>
{children}
</TorrentSortFilterContext.Provider>
<TorrentViewHashListContext.Provider value={torrentsState.viewHashList}>
<TorrentSortFilterContext.Provider value={[torrentSortFilterState, handleListSortFilter]}>
{children}
</TorrentSortFilterContext.Provider>
</TorrentViewHashListContext.Provider>
</TorrentHashListContext.Provider>
</TorrentsContext.Provider>
</ServerContext.Provider>
Expand All @@ -259,6 +262,10 @@ export const useTorrentList = () => {
return useContext(TorrentHashListContext);
};

export const useTorrentViewList = () => {
return useContext(TorrentViewHashListContext);
};

export const useTorrentSortFilterState = () => {
return useContext(TorrentSortFilterContext);
};
6 changes: 2 additions & 4 deletions src/components/torrents/selection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import produce from 'immer';
import { useEffect, useRef, useState } from 'react';
import { useTorrentList, useUiState } from '../state';
import { useTorrentViewList, useUiState } from '../state';
import { ROW_CELL_HEIGHT } from './list';
import { color, getElementAttr } from '../../utils';
import { mStyles } from '../common';
Expand Down Expand Up @@ -36,7 +36,7 @@ const initialState = {

export const TorrentListSelection = () => {
const classes = useStyles();
const hashList = useTorrentList();
const hashList = useTorrentViewList();
const [{ torrentListSelection }, { updateTorrentSelectionList, updateContextMenuIsOpen }] = useUiState();
const [state, setState] = useState(initialState);
const isUpdatingEndRef = useRef(false);
Expand Down Expand Up @@ -199,5 +199,3 @@ function getRectBound(state: typeof initialState) {

return result;
}

function getSelectionRange() {}

0 comments on commit c90360a

Please sign in to comment.