-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1666 from guardian/ag/convert-feast-collection
Ability to convert a container to a Feast collection and vice-versa
- Loading branch information
Showing
11 changed files
with
199 additions
and
22 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
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
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
55 changes: 55 additions & 0 deletions
55
...ts-client/src/components/FrontsEdit/CollectionComponents/DragToConvertFeastCollection.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,55 @@ | ||
import React, { useRef } from 'react'; | ||
import { DraggingArticleComponent } from './ArticleDrag'; | ||
import { DragToAdd } from './DragToAdd'; | ||
import { Card } from '../../../types/Collection'; | ||
import { CardTypesMap } from '../../../constants/cardTypes'; | ||
import v4 from 'uuid/v4'; | ||
import { handleDragStartForCard } from '../../../util/dragAndDrop'; | ||
import { useSelector } from 'react-redux'; | ||
import { selectors as collectionSelectors } from '../../../bundles/collectionsBundle'; | ||
import { createSelectCardsInCollection } from '../../../selectors/shared'; | ||
import { State } from '../../../types/State'; | ||
|
||
interface DragToConvertFeastCollectionProps { | ||
sourceContainerId: string; | ||
} | ||
|
||
export const DragToConvertFeastCollection:React.FC<DragToConvertFeastCollectionProps> = ({sourceContainerId})=>{ | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
const containerInfo = useSelector(state=>collectionSelectors.selectById(state, sourceContainerId)); | ||
const cardSelector = createSelectCardsInCollection(); | ||
const cards = useSelector<State>(state=>cardSelector(state, { | ||
collectionId: sourceContainerId, | ||
collectionSet: "draft", | ||
includeSupportingArticles: false | ||
})) as string[]; | ||
|
||
const handleDragStart = (event: React.DragEvent<HTMLDivElement>) => { | ||
if(ref.current) { | ||
const feastCollectionCard: Card = { | ||
cardType: CardTypesMap.FEAST_COLLECTION, | ||
id: v4(), | ||
meta: { | ||
title: containerInfo?.displayName ?? "New collection", | ||
supporting: cards, | ||
}, | ||
uuid: v4(), | ||
frontPublicationDate: Date.now(), | ||
}; | ||
|
||
return handleDragStartForCard( | ||
CardTypesMap.FEAST_COLLECTION, | ||
feastCollectionCard | ||
)(event, ref.current); | ||
} | ||
} | ||
|
||
return ( | ||
<DragToAdd onDragStart={handleDragStart} | ||
dragImage={<DraggingArticleComponent headline="Feast collection" />} | ||
dragImageRef={ref}> | ||
Drag to convert to Feast collection | ||
</DragToAdd> | ||
) | ||
} |
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
Oops, something went wrong.