Skip to content

Commit

Permalink
Add Chef to drag and drop actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Divs-B committed May 7, 2024
1 parent 5a4356d commit 2032f2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions fronts-client/src/util/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from 'util/url';
import { Recipe } from '../types/Recipe';
import type { CardTypes } from '../constants/cardTypes';
import { Chef } from '../types/Chef';

interface CreateCardOptions {
cardType?: CardTypes;
Expand Down Expand Up @@ -170,6 +171,10 @@ const getCardEntitiesFromDrop = async (
return getRecipeEntityFromFeedDrop(drop.data);
}

if (drop.type === 'CHEF') {
return getChefEntityFromFeedDrop(drop.data);
}

const droppedDataURL = drop.data.trim();
const resourceIdOrUrl = isGoogleRedirectUrl(droppedDataURL)
? getRelevantURLFromGoogleRedirectURL(droppedDataURL)
Expand Down Expand Up @@ -273,6 +278,11 @@ const getCardEntitiesFromDrop = async (
return [];
};

const getChefEntityFromFeedDrop = (chef: Chef): [Card] => {
const card = createCard(chef.id, false, { cardType: 'chef' });
return [card];
};

const getRecipeEntityFromFeedDrop = (recipe: Recipe): [Card] => {
const card = createCard(recipe.id, false, { cardType: 'recipe' });

Expand Down
12 changes: 11 additions & 1 deletion fronts-client/src/util/collectionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PosSpec } from 'lib/dnd';
import { insertCardWithCreate } from 'actions/Cards';
import { CapiArticle } from 'types/Capi';
import { Recipe } from '../types/Recipe';
import { Chef } from '../types/Chef';

export interface RefDrop {
type: 'REF';
Expand All @@ -19,7 +20,12 @@ export interface RecipeDrop {
data: Recipe;
}

export type MappableDropType = RefDrop | CAPIDrop | RecipeDrop;
export interface ChefDrop {
type: 'CHEF';
data: Chef;
}

export type MappableDropType = RefDrop | CAPIDrop | RecipeDrop | ChefDrop;

const dropToCard = (e: React.DragEvent): MappableDropType | null => {
const map = {
Expand All @@ -31,6 +37,10 @@ const dropToCard = (e: React.DragEvent): MappableDropType | null => {
type: 'RECIPE',
data: JSON.parse(data),
}),
chef: (data: string): ChefDrop => ({
type: 'CHEF',
data: JSON.parse(data),
}),
text: (url: string): RefDrop => ({ type: 'REF', data: url }),
};

Expand Down

0 comments on commit 2032f2f

Please sign in to comment.