Skip to content

Commit

Permalink
Lint files to remove red ink
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonherbert committed Feb 27, 2024
1 parent 5738aad commit c7ebca8
Show file tree
Hide file tree
Showing 67 changed files with 1,160 additions and 1,142 deletions.
1 change: 1 addition & 0 deletions fronts-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "src/index.js",
"license": "MIT",
"scripts": {
"compileWithBabel": "node -r @babel/register",
"bundle": "yarn compileWithBabel $(yarn bin)/webpack",
"build": "yarn bundle --config config/webpack.config.prod.js",
"watch": "yarn bundle --config config/webpack.config.dev.js --watch",
Expand Down
263 changes: 132 additions & 131 deletions fronts-client/src/actions/Cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ import {
// the persistence stuff needs to be dynamic as we sometimes need to insert an
// card and save to clipboard and sometimes save to collection
// depending on the location of that card
const createInsertCardThunk = (action: InsertActionCreator) => (
persistTo: 'collection' | 'clipboard'
) => (id: string, index: number, cardId: string, removeAction?: Action) => (
dispatch: Dispatch
) => {
if (removeAction) {
dispatch(removeAction);
}
// This cast seems to be necessary to disambiguate the type fed to Dispatch,
// whose call signature accepts either an Action or a ThunkResult. I'm not really
// sure why.
dispatch(action(id, index, cardId, persistTo) as Action);
};
const createInsertCardThunk =
(action: InsertActionCreator) =>
(persistTo: 'collection' | 'clipboard') =>
(id: string, index: number, cardId: string, removeAction?: Action) =>
(dispatch: Dispatch) => {
if (removeAction) {
dispatch(removeAction);
}
// This cast seems to be necessary to disambiguate the type fed to Dispatch,
// whose call signature accepts either an Action or a ThunkResult. I'm not really
// sure why.
dispatch(action(id, index, cardId, persistTo) as Action);
};

const copyCardImageMetaWithPersist = addPersistMetaToAction(copyCardImageMeta, {
persistTo: 'collection',
Expand All @@ -73,83 +73,81 @@ const copyCardImageMetaWithPersist = addPersistMetaToAction(copyCardImageMeta, {
// Creates a thunk with persistence that will launch a confirm modal if required
// when adding to a group, otherwise will just run the action
// the confirm modal links to the collection caps
const maybeInsertGroupCard = (persistTo: 'collection' | 'clipboard') => (
id: string,
index: number,
cardId: string,
removeAction?: Action
) => {
return (dispatch: Dispatch, getState: () => State) => {
// require a modal!
const state = getState();

const collectionCap = selectCollectionCap(state);

const willCollectionHitCollectionCap = selectWillCollectionHitCollectionCap(
state,
id,
index,
cardId,
collectionCap
);
const maybeInsertGroupCard =
(persistTo: 'collection' | 'clipboard') =>
(id: string, index: number, cardId: string, removeAction?: Action) => {
return (dispatch: Dispatch, getState: () => State) => {
// require a modal!
const state = getState();

const collectionCap = selectCollectionCap(state);

const willCollectionHitCollectionCap =
selectWillCollectionHitCollectionCap(
state,
id,
index,
cardId,
collectionCap
);

const confirmRemoval = () => {
const actions = [];
const confirmRemoval = () => {
const actions = [];

if (removeAction) {
actions.push(removeAction);
}
if (removeAction) {
actions.push(removeAction);
}

actions
.concat([
insertGroupCard(id, index, cardId, persistTo),
maybeAddFrontPublicationDate(cardId),
addPersistMetaToAction(capGroupSiblings, {
id: cardId,
persistTo,
applyBeforeReducer: true,
})(id, collectionCap),
])
.forEach((action) => dispatch(action));
};
actions
.concat([
insertGroupCard(id, index, cardId, persistTo),
maybeAddFrontPublicationDate(cardId),
addPersistMetaToAction(capGroupSiblings, {
id: cardId,
persistTo,
applyBeforeReducer: true,
})(id, collectionCap),
])
.forEach((action) => dispatch(action));
};

if (willCollectionHitCollectionCap) {
// if there are too many cards now then launch a modal to ask the user
// what action to take
dispatch(
startOptionsModal(
'Collection limit',
`You can have a maximum of ${collectionCap} articles in a collection.
if (willCollectionHitCollectionCap) {
// if there are too many cards now then launch a modal to ask the user
// what action to take
dispatch(
startOptionsModal(
'Collection limit',
`You can have a maximum of ${collectionCap} articles in a collection.
You can proceed, and the last article in the collection will be
removed automatically, or you can cancel and remove articles from the
collection yourself.`,
// if the user accepts, then remove the moved item (if there was one),
// remove cards past the cap count and finally persist
[
{
buttonText: 'Confirm',
callback: confirmRemoval,
},
],
// otherwise do nothing
noop,
true
)
);
} else {
// if we're not going over the cap then just remove a moved article if
// needed and insert the new article
dispatch(
batchActions(
(removeAction ? [removeAction] : []).concat([
maybeAddFrontPublicationDate(cardId),
insertGroupCard(id, index, cardId, persistTo),
])
)
);
}
// if the user accepts, then remove the moved item (if there was one),
// remove cards past the cap count and finally persist
[
{
buttonText: 'Confirm',
callback: confirmRemoval,
},
],
// otherwise do nothing
noop,
true
)
);
} else {
// if we're not going over the cap then just remove a moved article if
// needed and insert the new article
dispatch(
batchActions(
(removeAction ? [removeAction] : []).concat([
maybeAddFrontPublicationDate(cardId),
insertGroupCard(id, index, cardId, persistTo),
])
)
);
}
};
};
};

const addActionMap: { [type: string]: InsertThunkActionCreator | undefined } = {
card: createInsertCardThunk(insertSupportingCard),
Expand Down Expand Up @@ -198,53 +196,55 @@ const updateCardMetaWithPersist = addPersistMetaToAction(updateCardMeta, {
persistTo: 'collection',
});

const insertCardWithCreate = (
to: PosSpec,
drop: MappableDropType,
persistTo: 'collection' | 'clipboard',
// allow the factory to be injected for testing
cardFactory = createArticleEntitiesFromDrop
): ThunkResult<void> => async (dispatch: Dispatch, getState) => {
const insertActionCreator = getInsertionActionCreatorFromType(
to.type,
persistTo
);
if (!insertActionCreator) {
return;
}
const state = getState();
const toWithRespectToState = getToGroupIndicesWithRespectToState(
to,
state,
false
);
if (toWithRespectToState) {
try {
const card = await dispatch(cardFactory(drop));
if (!card) {
return;
}
dispatch(
insertActionCreator(
toWithRespectToState.id,
toWithRespectToState.index,
card.uuid
)
);
const insertCardWithCreate =
(
to: PosSpec,
drop: MappableDropType,
persistTo: 'collection' | 'clipboard',
// allow the factory to be injected for testing
cardFactory = createArticleEntitiesFromDrop
): ThunkResult<void> =>
async (dispatch: Dispatch, getState) => {
const insertActionCreator = getInsertionActionCreatorFromType(
to.type,
persistTo
);
if (!insertActionCreator) {
return;
}
const state = getState();
const toWithRespectToState = getToGroupIndicesWithRespectToState(
to,
state,
false
);
if (toWithRespectToState) {
try {
const card = await dispatch(cardFactory(drop));
if (!card) {
return;
}
dispatch(
insertActionCreator(
toWithRespectToState.id,
toWithRespectToState.index,
card.uuid
)
);

// Fetch ophan data
const [frontId, collectionId] = selectOpenParentFrontOfCard(
getState(),
card.uuid
);
if (frontId && collectionId) {
await dispatch(getPageViewData(frontId, collectionId, [card.uuid]));
// Fetch ophan data
const [frontId, collectionId] = selectOpenParentFrontOfCard(
getState(),
card.uuid
);
if (frontId && collectionId) {
await dispatch(getPageViewData(frontId, collectionId, [card.uuid]));
}
} catch (e) {
// Insert failed -- @todo handle error
}
} catch (e) {
// Insert failed -- @todo handle error
}
}
};
};

const removeCard = (
type: string,
Expand Down Expand Up @@ -304,11 +304,12 @@ const moveCard = (
fromOrphanedGroup: boolean;
} = getFromGroupIndicesWithRespectToState(from, state);

const toWithRespectToState: PosSpec | null = getToGroupIndicesWithRespectToState(
to,
state,
fromDetails.fromOrphanedGroup
);
const toWithRespectToState: PosSpec | null =
getToGroupIndicesWithRespectToState(
to,
state,
fromDetails.fromOrphanedGroup
);
if (toWithRespectToState) {
const { fromWithRespectToState } = fromDetails;

Expand Down
3 changes: 2 additions & 1 deletion fronts-client/src/actions/CardsCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const REMOVE_SUPPORTING_CARD = 'REMOVE_SUPPORTING_CARD' as const;
export const INSERT_GROUP_CARD = 'INSERT_GROUP_CARD' as const;
export const INSERT_SUPPORTING_CARD = 'INSERT_SUPPORTING_CARD' as const;
export const COPY_CARD_IMAGE_META = 'COPY_CARD_IMAGE_META' as const;
export const MAYBE_ADD_FRONT_PUBLICATION = 'MAYBE_ADD_FRONT_PUBLICATION' as const;
export const MAYBE_ADD_FRONT_PUBLICATION =
'MAYBE_ADD_FRONT_PUBLICATION' as const;

function updateCardMeta(
id: string,
Expand Down
18 changes: 8 additions & 10 deletions fronts-client/src/actions/ClipboardThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import {
} from './Clipboard';
import { selectCards } from 'selectors/shared';

export const thunkInsertClipboardCard = (
id: string,
index: number,
cardId: string
): ThunkResult<void> => (dispatch, getState) => {
const currentCards = selectCards(getState());
dispatch(
actionInsertClipboardCardWithPersist(id, index, cardId, currentCards)
);
};
export const thunkInsertClipboardCard =
(id: string, index: number, cardId: string): ThunkResult<void> =>
(dispatch, getState) => {
const currentCards = selectCards(getState());
dispatch(
actionInsertClipboardCardWithPersist(id, index, cardId, currentCards)
);
};

export function storeClipboardContent(clipboardContent: NestedCard[]) {
return (dispatch: Dispatch) => {
Expand Down
Loading

0 comments on commit c7ebca8

Please sign in to comment.