-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf8cbbf
commit 5f41058
Showing
5 changed files
with
144 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
frontend/components/projects/edit/information/SortableProjectLinkItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import ListItem from '@mui/material/ListItem' | ||
import ListItemText from '@mui/material/ListItemText' | ||
import SortableListItemActions from '~/components/layout/SortableListItemActions' | ||
|
||
import {useSortable} from '@dnd-kit/sortable' | ||
import {CSS} from '@dnd-kit/utilities' | ||
import {ProjectLink} from '~/types/Project' | ||
|
||
type SortableProjectLinkProps = { | ||
pos: number, | ||
item: ProjectLink, | ||
onEdit: (pos: number) => void, | ||
onDelete: (pos: number) => void, | ||
} | ||
|
||
|
||
export default function SortableProjectLinksItem({pos, item, onEdit, onDelete}: SortableProjectLinkProps) { | ||
const { | ||
attributes,listeners,setNodeRef, | ||
transform,transition,isDragging | ||
} = useSortable({id: item.id ?? ''}) | ||
return( | ||
<ListItem | ||
// draggable | ||
ref={setNodeRef} | ||
{...attributes} | ||
// disableGutters | ||
secondaryAction={ | ||
<SortableListItemActions | ||
pos={pos} | ||
listeners={listeners} | ||
onEdit={onEdit} | ||
onDelete={onDelete} | ||
/> | ||
} | ||
sx={{ | ||
// this makes space for buttons | ||
paddingRight: '11rem', | ||
// fixed height to avoid deformed item during dragging | ||
// height:'4rem', | ||
'&:hover': { | ||
backgroundColor:'grey.100' | ||
}, | ||
transform: CSS.Transform.toString(transform), | ||
transition, | ||
opacity: isDragging ? 0.5 : 1, | ||
backgroundColor: isDragging ? 'grey.100' : 'paper', | ||
zIndex: isDragging ? 9:0, | ||
cursor: isDragging ? 'move' : 'default' | ||
}} | ||
> | ||
<ListItemText | ||
disableTypography | ||
primary={ | ||
<a href={item.url ?? undefined} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
{item.title} | ||
</a> | ||
} | ||
/> | ||
</ListItem> | ||
) | ||
} |
32 changes: 32 additions & 0 deletions
32
frontend/components/projects/edit/information/SortableProjectLinksList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import SortableList from '~/components/layout/SortableList' | ||
import {ProjectLink} from '~/types/Project' | ||
import SortableProjectLinksItem from './SortableProjectLinkItem' | ||
|
||
type SortableProjectLinksListProps = { | ||
links: ProjectLink[], | ||
onEdit: (pos: number) => void | ||
onDelete: (pos: number) => void | ||
onSorted: (link:ProjectLink[])=>void | ||
} | ||
|
||
|
||
export default function SortableProjectLinksList({links,onEdit,onDelete,onSorted}:SortableProjectLinksListProps) { | ||
|
||
function onRenderItem(item:ProjectLink,index?:number) { | ||
return <SortableProjectLinksItem | ||
key={item.id ?? index} | ||
pos={index ?? 0} | ||
item={item} | ||
onEdit={onEdit} | ||
onDelete={onDelete} | ||
/> | ||
} | ||
|
||
return ( | ||
<SortableList | ||
items={links} | ||
onSorted={onSorted} | ||
onRenderItem={onRenderItem} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters