Skip to content

Commit

Permalink
refactor: apply PR requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Sep 27, 2024
1 parent 4766945 commit 8ac8fed
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
15 changes: 6 additions & 9 deletions src/components/item/FolderContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import {
SelectionContextProvider,
useSelectionContext,
} from '../main/list/SelectionContext';
import { useDragSelection } from '../main/list/useDragSelection';
import {
DragContainerStack,
useDragSelection,
} from '../main/list/useDragSelection';
import { DesktopMap } from '../map/DesktopMap';
import NoItemFilters from '../pages/NoItemFilters';
import { OutletType } from '../pages/item/type';
Expand Down Expand Up @@ -75,13 +78,7 @@ const Content = ({
if (items?.length) {
return (
<>
<Stack
// this is a hack to allow selection dragging from margin
mx={-100}
px={100}
height="100%"
id={CONTAINER_ID}
>
<DragContainerStack id={CONTAINER_ID}>
<ItemsTable
selectedIds={selectedIds}
enableMoveInBetween={sortBy === SortingOptionsForFolder.Order}
Expand All @@ -100,7 +97,7 @@ const Content = ({
/>
</Stack>
)}
</Stack>
</DragContainerStack>
{DragSelection}
</>
);
Expand Down
26 changes: 25 additions & 1 deletion src/components/main/list/useDragSelection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useState } from 'react';
import { ReactNode, useState } from 'react';

import { Stack } from '@mui/material';

import { PRIMARY_COLOR } from '@graasp/ui';

Expand All @@ -12,6 +14,28 @@ import { ITEM_CARD_CLASS } from '@/config/selectors';

import { useSelectionContext } from './SelectionContext';

export const DragContainerStack = ({
gap,
id,
children,
}: {
gap?: number;
id: string;
children: ReactNode;
}): JSX.Element => (
<Stack
// this is a hack to allow selection dragging from margin
// 100 is artbitrary big
mx={-100}
px={100}
height="100%"
id={id}
gap={gap}
>
{children}
</Stack>
);

export const useDragSelection = ({
elementClass = ITEM_CARD_CLASS,
containerId,
Expand Down
16 changes: 6 additions & 10 deletions src/components/pages/RecycledItemsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
SelectionContextProvider,
useSelectionContext,
} from '../main/list/SelectionContext';
import { useDragSelection } from '../main/list/useDragSelection';
import {
DragContainerStack,
useDragSelection,
} from '../main/list/useDragSelection';
import ItemCard from '../table/ItemCard';
import SortingSelect from '../table/SortingSelect';
import { SortingOptions } from '../table/types';
Expand Down Expand Up @@ -93,14 +96,7 @@ const RecycledItemsScreenContent = ({
</Stack>
)}
</Stack>
<Stack
// this is a hack to allow selection dragging from margin
mx={-100}
px={100}
id={CONTAINER_ID}
gap={1}
height="100%"
>
<DragContainerStack id={CONTAINER_ID}>
{
// render the filtered data and when it is empty display that nothing matches the search
filteredData?.length ? (
Expand All @@ -127,7 +123,7 @@ const RecycledItemsScreenContent = ({
</Alert>
)
}
</Stack>
</DragContainerStack>
</Stack>
{DragSelection}
</>
Expand Down
15 changes: 6 additions & 9 deletions src/components/pages/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
SelectionContextProvider,
useSelectionContext,
} from '@/components/main/list/SelectionContext';
import { useDragSelection } from '@/components/main/list/useDragSelection';
import {
DragContainerStack,
useDragSelection,
} from '@/components/main/list/useDragSelection';
import { ITEM_PAGE_SIZE } from '@/config/constants';
import { ShowOnlyMeChangeType } from '@/config/types';
import { ItemLayoutMode, Ordering } from '@/enums';
Expand Down Expand Up @@ -107,13 +110,7 @@ const HomeScreenContent = ({ searchText }: { searchText: string }) => {
? data.pages.map(({ data: d }) => d.length).reduce((a, b) => a + b, 0)
: 0;
content = (
<Stack
// this is a hack to allow selection dragging from margin
mx={-100}
px={100}
id={CONTAINER_ID}
height="100%"
>
<DragContainerStack id={CONTAINER_ID}>
<ItemsTable
canMove={!searchText}
id={ACCESSIBLE_ITEMS_TABLE_ID}
Expand All @@ -136,7 +133,7 @@ const HomeScreenContent = ({ searchText }: { searchText: string }) => {
<NewItemButton type="icon" />
</Stack>
)}
</Stack>
</DragContainerStack>
);
} else if (itemTypes.length || searchText) {
content = <NoItemFilters searchText={searchText} />;
Expand Down

0 comments on commit 8ac8fed

Please sign in to comment.