2023-12-15 13:49:54 +08:00
|
|
|
import {DialogPopup} from "./options/DialogPopup";
|
|
|
|
import React from "react";
|
|
|
|
import {useShopStore} from "./shop_store";
|
|
|
|
import {SummaryPopup} from "./options/SummaryPopup";
|
|
|
|
|
|
|
|
export function OptionsDialogWrapper({crate_index, card_index, first, last}) {
|
|
|
|
const crate_id = useShopStore((state) => state.crates[crate_index].id);
|
|
|
|
const options = useShopStore((state) => state.crates[crate_index].items[card_index].options);
|
|
|
|
const options_data = useShopStore((state) => state.crates[crate_index].items[card_index].options_data);
|
|
|
|
const card_size = useShopStore((state) => state.crates[crate_index].items[card_index].size);
|
|
|
|
const options_class = useShopStore((state) => state.crates[crate_index].items[card_index].options_class);
|
|
|
|
|
|
|
|
const onOptionsUpdate = useShopStore((state) => state.updateOptions);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DialogPopup
|
|
|
|
options={options}
|
|
|
|
data={options_data}
|
|
|
|
options_class={options_class}
|
2024-01-02 17:13:50 +08:00
|
|
|
key={"popover" + crate_id +card_index}
|
|
|
|
id={"popover"+ crate_id + card_index}
|
2023-12-15 13:49:54 +08:00
|
|
|
big={card_size === "big"}
|
|
|
|
first={first}
|
|
|
|
last={last}
|
|
|
|
target={{
|
|
|
|
construct: ((outvar, value) => {
|
2024-01-02 17:13:50 +08:00
|
|
|
// #!options_log
|
|
|
|
console.log("construct", outvar, value, options_data);
|
|
|
|
|
2023-12-15 13:49:54 +08:00
|
|
|
options_data[outvar] = value;
|
|
|
|
}),
|
|
|
|
update: ((outvar, value) => {
|
2024-01-02 17:13:50 +08:00
|
|
|
// #!options_log
|
|
|
|
console.log("update", outvar, value, options_data);
|
|
|
|
|
2023-12-15 13:49:54 +08:00
|
|
|
if (outvar in options_data) options_data[outvar] = value;
|
|
|
|
onOptionsUpdate(crate_id, card_index, {[outvar]: value});
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function OptionsSummaryWrapper({crate_index, card_index}) {
|
|
|
|
const card_id = useShopStore((state) => state.crates[crate_index].items[card_index].id);
|
|
|
|
const options = useShopStore((state) => state.crates[crate_index].items[card_index].options);
|
|
|
|
const options_data = useShopStore((state) => state.crates[crate_index].items[card_index].options_data);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SummaryPopup id={card_id + "options"} options={options}
|
|
|
|
data={options_data}/>
|
|
|
|
)
|
|
|
|
}
|