Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 356x 8x 8x 8x 1x 8x 1x 8x 7x 1x 1x 8x 8x | import { ProgramItem } from "shared/types/models/programItem";
import { submitUpdateFavorites } from "client/views/my-program-items/myProgramItemsThunks";
import { AppDispatch } from "client/types/reduxTypes";
export interface UpdateFavoriteOpts {
programItem: ProgramItem;
action: string;
favoriteProgramItems: readonly ProgramItem[];
username: string;
dispatch: AppDispatch;
}
export const updateFavorite = async (
updateFavoriteOpts: UpdateFavoriteOpts,
): Promise<void> => {
const { programItem, action, favoriteProgramItems, username, dispatch } =
updateFavoriteOpts;
Iif (!programItem.programItemId) {
return;
}
const programItemIndex = favoriteProgramItems.findIndex(
(favoriteProgramItem) =>
favoriteProgramItem.programItemId === programItem.programItemId,
);
const favoriteProgramItemIds = favoriteProgramItems.map(
(favoriteProgramItem) => favoriteProgramItem.programItemId,
);
if (action === "add" && programItemIndex === -1) {
favoriteProgramItemIds.push(programItem.programItemId);
} else Eif (action === "del" && programItemIndex > -1) {
favoriteProgramItemIds.splice(programItemIndex, 1);
}
const error = await dispatch(
submitUpdateFavorites({
username,
favoriteProgramItemIds,
}),
);
Iif (error) {
// eslint-disable-next-line no-restricted-syntax -- TODO: Remove throw
throw new Error(`submitUpdateFavorites error: ${error}`);
}
};
|