deleting items syncing

This commit is contained in:
michael-grace 2020-11-15 20:11:48 +00:00
parent 99f1de735b
commit c7bf1cc573
3 changed files with 30 additions and 3 deletions

View file

@ -1,8 +1,9 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { Dispatch, Middleware } from "redux"; import { Dispatch, Middleware } from "redux";
import { TimeslotItem } from "./api";
import { load, pause, play, seek, stop } from "./mixer/state"; import { load, pause, play, seek, stop } from "./mixer/state";
import { RootState } from "./rootReducer"; import { RootState } from "./rootReducer";
import { PlanItem } from "./showplanner/state"; import { PlanItem, removeItem } from "./showplanner/state";
import { AppThunk } from "./store"; import { AppThunk } from "./store";
interface Connection { interface Connection {
@ -65,6 +66,23 @@ export const bapsicleMiddleware: Middleware<{}, RootState, Dispatch<any>> = (
}); });
store.dispatch(load(message.channel, itemToLoad!)); store.dispatch(load(message.channel, itemToLoad!));
break; break;
case "REMOVE":
var itemToRemove: PlanItem;
store.getState().showplan.plan?.forEach((item) => {
if (
item.channel === message.channel &&
item.weight === message.weight
) {
itemToRemove = item;
}
});
store.dispatch(
removeItem(
store.getState().session.currentTimeslot!.timeslot_id,
(itemToRemove! as TimeslotItem).timeslotitemid
)
);
break;
} }
} else if ("message" in message) { } else if ("message" in message) {
if (message.message === "Hello") { if (message.message === "Hello") {

View file

@ -70,7 +70,7 @@ export const Item = memo(function Item({
> >
<ContextMenuTrigger <ContextMenuTrigger
id={isReal ? TS_ITEM_MENU_ID : ""} id={isReal ? TS_ITEM_MENU_ID : ""}
collect={() => ({ id })} collect={() => ({ id, column, index })}
> >
<span className={"icon " + x.type} /> <span className={"icon " + x.type} />
&nbsp; &nbsp;

View file

@ -40,6 +40,7 @@ import { Player } from "./Player";
import { CombinedNavAlertBar } from "../navbar"; import { CombinedNavAlertBar } from "../navbar";
import "./channel.scss"; import "./channel.scss";
import Modal from "react-modal"; import Modal from "react-modal";
import { sendBAPSicleChannel } from "../bapsicle";
function Channel({ id, data }: { id: number; data: PlanItem[] }) { function Channel({ id, data }: { id: number; data: PlanItem[] }) {
return ( return (
@ -231,7 +232,15 @@ const Showplanner: React.FC<{ timeslotId: number }> = function({ timeslotId }) {
} }
} }
async function onCtxRemoveClick(e: any, data: { id: string }) { async function onCtxRemoveClick(
e: any,
data: { id: string; column: number; index: number }
) {
sendBAPSicleChannel({
channel: data.column,
command: "REMOVE",
weight: data.index,
});
dispatch(removeItem(timeslotId, data.id)); dispatch(removeItem(timeslotId, data.id));
} }
async function onCtxUnPlayedClick(e: any, data: { id: string }) { async function onCtxUnPlayedClick(e: any, data: { id: string }) {