diff --git a/client/src/components/ChoreWidget.jsx b/client/src/components/ChoreWidget.jsx
index 506e1aa1..8d7ce925 100644
--- a/client/src/components/ChoreWidget.jsx
+++ b/client/src/components/ChoreWidget.jsx
@@ -24,6 +24,7 @@ import {
ListItemText,
ListItemIcon,
List,
+ ListItem,
ListItemButton,
ListItemAvatar,
Radio,
@@ -41,7 +42,8 @@ import { API_BASE_URL } from '../utils/apiConfig.js';
import { pinErrorText } from '../utils/pinErrors.js';
import { getDeviceApiBase } from '../utils/deviceName.js';
import { fetchPinRemembered, setPinRemembered, shouldPromptForPin } from '../utils/adminPinDevice.js';
-import { shouldShowChoreToday, getTodayDateString, getDueDateStatus, formatDueDate, hasOutstandingBonusChore, canClaimBonusChore, countsTowardDailyBonus, getTransferTargets } from '../utils/choreHelpers.js';
+import { shouldShowChoreToday, getTodayDateString, getDueDateStatus, formatDueDate, hasOutstandingBonusChore, canClaimBonusChore, countsTowardDailyBonus, getTransferTargets, splitStars, splitShareFor, splitShareDoneFor, splitHasTickedShare, isSplitSchedule } from '../utils/choreHelpers.js';
+import { createPressHold } from '../utils/pressHold.js';
import { filterVisibleUsers, toggleHiddenUserId, pruneHiddenUserIds } from '../utils/choreUserVisibility.js';
import { isControlHidden } from '../utils/displayControls.js';
import { subscribePluginEvents } from '../utils/pluginEventBridge.js';
@@ -172,6 +174,13 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
// Long-press / right-click chore menu and its follow-up dialogs (issue #122).
const [choreMenu, setChoreMenu] = useState({ position: null, schedule: null });
const [transferDialog, setTransferDialog] = useState({ open: false, schedule: null, targetUserId: null, mode: 'keep', bonus: 1 });
+ // Splitting a bonus chore's Stars among several people: long-press a
+ // bonus card to open the picker, pick at least two people, and each gets
+ // their share. `result` holds the confirmed split to show in the dialog.
+ const [splitDialog, setSplitDialog] = useState({ open: false, schedule: null, userIds: [], result: null });
+ const splitPressHoldRef = useRef(null);
+ const splitHoldFiredRef = useRef(false);
+ const splitDialogOpenedAtRef = useRef(0);
const [columnsRef, columnsFadeSx] = useEdgeFade();
const [snoozeDialog, setSnoozeDialog] = useState({ open: false, schedule: null, until: '' });
const [historyDialog, setHistoryDialog] = useState({ open: false, schedule: null });
@@ -204,6 +213,7 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
// at all.
const hideAddChore = isControlHidden(hiddenControls, 'core:addChore');
const hideTransferChore = isControlHidden(hiddenControls, 'core:transferChore');
+ const hideSplitChore = isControlHidden(hiddenControls, 'core:splitChore');
const hideSnoozeChore = isControlHidden(hiddenControls, 'core:snoozeChore');
const hidePrizeApproval = isControlHidden(hiddenControls, 'core:prizeApproval');
const hideQuickSpend = isControlHidden(hiddenControls, 'core:quickSpend');
@@ -221,6 +231,9 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
if (hideTransferChore) {
setTransferDialog((prev) => (prev.open ? { ...prev, open: false } : prev));
}
+ if (hideSplitChore) {
+ setSplitDialog((prev) => (prev.open ? { ...prev, open: false } : prev));
+ }
if (hideSnoozeChore) {
setSnoozeDialog((prev) => (prev.open ? { ...prev, open: false } : prev));
}
@@ -232,7 +245,7 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
if (hideTransferChore && hideSnoozeChore) {
setChoreMenu((prev) => (prev.position ? { position: null, schedule: null } : prev));
}
- }, [hideAddChore, hideTransferChore, hideSnoozeChore, hideQuickSpend]);
+ }, [hideAddChore, hideTransferChore, hideSplitChore, hideSnoozeChore, hideQuickSpend]);
useEffect(() => {
fetchData();
@@ -741,14 +754,18 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
}
// A tap already in flight for this chore: ignore the second one rather
// than POSTing twice (the second would 409 and snap the row back).
- if (pendingToggles[schedule.id] !== undefined) return;
+ // A split schedule shows in several columns at once: one person's tap
+ // must not block another's, so the in-flight tap is keyed by schedule
+ // AND person.
+ const pendingKey = `${schedule.id}:${schedule.user_id}`;
+ if (pendingToggles[pendingKey] !== undefined) return;
const today = getTodayDateString();
// Flip the row now; the server round-trip happens behind it. No
// full-screen spinner: a checkbox tap should never block the widget.
- setPendingToggles((prev) => ({ ...prev, [schedule.id]: !isCompleted }));
+ setPendingToggles((prev) => ({ ...prev, [pendingKey]: !isCompleted }));
const clearPending = () => setPendingToggles((prev) => {
const next = { ...prev };
- delete next[schedule.id];
+ delete next[pendingKey];
return next;
});
try {
@@ -817,6 +834,57 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
}
};
+ // ---- Splitting a bonus chore's Stars ------------------------------------
+ // Long-press a bonus card (or right-click it) to open the picker: tick
+ // the people sharing the chore and each gets their share, the leftover
+ // Stars going one each to the first people picked. Confirming posts to
+ // the split route, which keeps the one pool schedule and records the
+ // split on it — the card then shows in each person's column, and each
+ // person ticks their own share. The result stays in the dialog — there
+ // is no toast system on the dashboard — until Done closes it.
+ const openSplitDialog = (schedule) => {
+ if (!schedule || hideSplitChore) return;
+ splitDialogOpenedAtRef.current = Date.now();
+ setSplitDialog((prev) => (prev.open ? prev : { open: true, schedule, userIds: [], result: null }));
+ };
+
+ const closeSplitDialog = () => setSplitDialog({ open: false, schedule: null, userIds: [], result: null });
+
+ const toggleBonusSplitUser = (userId) => {
+ setSplitDialog((prev) => ({
+ ...prev,
+ userIds: prev.userIds.includes(userId)
+ ? prev.userIds.filter((id) => id !== userId)
+ : [...prev.userIds, userId],
+ }));
+ };
+
+ const confirmSplit = async () => {
+ const { schedule, userIds } = splitDialog;
+ if (!schedule || userIds.length < 2) return;
+ try {
+ setIsLoading(true);
+ const response = await axios.post(`${API_BASE_URL}/api/chore-schedules/${schedule.id}/split-assign`, { userIds });
+ const updated = response.data?.schedule;
+ await fetchData();
+ // The split rides on the one schedule: read the shares back from it
+ // rather than assuming the picker preview, so the dialog shows
+ // exactly what the server recorded.
+ const ids = updated?.split_user_ids || userIds;
+ const shares = updated?.split_shares || splitStars(schedule.clam_value, userIds.length);
+ const parts = ids.map((id, index) => ({
+ username: users.find((u) => u.id === id)?.username || '?',
+ stars: shares[index],
+ }));
+ setSplitDialog((prev) => ({ ...prev, result: { total: schedule.clam_value, parts } }));
+ } catch (error) {
+ console.error('Error splitting bonus chore:', error);
+ alert(error.response?.data?.error || t('chores:bonus.splitFailed'));
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
const reassignChore = async (scheduleId, newUserId, extraFields = {}) => {
const schedule = schedules.find(s => s.id === scheduleId);
if (!schedule || schedule.user_id === newUserId) {
@@ -851,8 +919,14 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
// Control Limits fold in here rather than only at the MenuItem: hiding both
// items but still opening the menu leaves an empty popover over the chore,
// which reads as a bug and has to be dismissed before anything else works.
+ // A split with a ticked share is locked (issue #407): moving it would
+ // pay the ticked share plus the whole chore, so Transfer is hidden
+ // here as well as at the MenuItem — the server refuses it either way.
+ // The lock reads the server's split_done_user_ids, so a share ticked
+ // yesterday still locks it today.
const canTransfer = !hideTransferChore
&& schedule.transferable !== 0
+ && !splitHasTickedShare(schedule, history)
&& getTransferTargets(users, schedule.user_id, '', schedule).length > 0;
const canSnooze = !hideSnoozeChore && schedule.can_snooze !== 0;
// History is one person's record, so an unassigned bonus chore has none.
@@ -925,6 +999,65 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
}
};
+ // ---- Press-and-hold on a bonus card: the split picker -------------------
+ // The chore menu's timer is touch-only (mouse users right-click); a
+ // bonus card's hold works for touch and mouse alike, so a desktop hold
+ // reaches the same picker. The pressHold util (utils/pressHold.js)
+ // cancels on a slide, and the release after a hold is swallowed below
+ // so it cannot also claim the chore.
+ const getSplitPressHold = () => {
+ if (!splitPressHoldRef.current) {
+ splitPressHoldRef.current = createPressHold({
+ onHold: (schedule) => {
+ splitHoldFiredRef.current = true;
+ openSplitDialog(schedule);
+ },
+ });
+ }
+ return splitPressHoldRef.current;
+ };
+
+ const handleBonusCardPointerDown = (event, schedule) => {
+ if (hideSplitChore) return;
+ splitHoldFiredRef.current = false;
+ getSplitPressHold().down(event.clientX, event.clientY, schedule);
+ };
+
+ const handleBonusCardPointerMove = (event) => {
+ getSplitPressHold().move(event.clientX, event.clientY);
+ };
+
+ const handleBonusCardPointerEnd = () => {
+ getSplitPressHold().up();
+ };
+
+ const handleBonusCardPointerCancel = () => {
+ getSplitPressHold().cancel();
+ };
+
+ const handleBonusCardContextMenu = (event, schedule) => {
+ // Hidden means NOT RENDERED: the hold never starts, and right-click
+ // falls through to the native menu instead of opening the picker.
+ if (hideSplitChore) return;
+ // Always suppress the native browser menu on bonus cards so right-click
+ // (and Android long-press) opens the split picker instead. A
+ // long-press-generated contextmenu (button 0) follows the hold that
+ // already opened the picker; the open guard in openSplitDialog drops it.
+ event.preventDefault();
+ if (event.button !== 2) {
+ splitHoldFiredRef.current = true;
+ }
+ openSplitDialog(schedule);
+ };
+
+ const handleBonusCardClickCapture = (event) => {
+ if (splitHoldFiredRef.current) {
+ event.preventDefault();
+ event.stopPropagation();
+ splitHoldFiredRef.current = false;
+ }
+ };
+
// Mirrors the server's daily-bonus rule: a user's day is complete when they
// have at least one regular (zero-clam) chore today and none are open. A
// follow-up handed out today doesn't count yet (issue #241).
@@ -1097,23 +1230,36 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
const getUserChoresForToday = (userId) => {
return schedules
.filter(schedule => {
- if (schedule.user_id !== userId) return false;
+ // A split schedule shows in every selected person's column: the
+ // card is the same chore, stamped below with this person's share.
+ const splitShare = splitShareFor(schedule, userId);
+ if (schedule.user_id !== userId && splitShare === null) return false;
if (!schedule.visible) return false;
return shouldShowChoreToday(schedule);
})
.map(schedule => {
const today = getTodayDateString();
- const pending = pendingToggles[schedule.id];
+ const pending = pendingToggles[`${schedule.id}:${userId}`];
+ // A split share is done once the member ticks it — on or after the
+ // split's claim date, which the server attaches as
+ // split_done_user_ids, so a share ticked yesterday still shows as
+ // done today (issue #407). Today's history alone cannot see it.
const completed = pending !== undefined
? pending
: history.some(h =>
h.chore_schedule_id === schedule.id &&
h.user_id === userId &&
h.date === today
- );
+ ) || splitShareDoneFor(schedule, userId, history, today);
+ // A split card belongs to this column's person: ticking it is
+ // theirs, and the Stars shown are their share — the chore's full
+ // Stars stay on the pool card only.
+ const splitShare = splitShareFor(schedule, userId);
return {
...schedule,
+ user_id: userId,
+ ...(splitShare !== null ? { split_share: splitShare } : {}),
completed,
pending: pending !== undefined,
id: schedule.id
@@ -1126,7 +1272,9 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
};
const getAvailableBonusChores = () => {
- return getBonusChores().filter(schedule => schedule.user_id === null || schedule.user_id === 0);
+ // A split chore is no longer in the pool: it is already claimed, one
+ // share per person, and shows in each person's column instead.
+ return getBonusChores().filter(schedule => (schedule.user_id === null || schedule.user_id === 0) && !isSplitSchedule(schedule));
};
// `size` and `badge`: the column header draws a smaller avatar and shows the
@@ -1343,7 +1491,7 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
chips: the title stays the loudest thing in the row. */}
{schedule.clam_value > 0 && (
- {t('common:points.gain', { amount: schedule.clam_value })}
+ {t('common:points.gain', { amount: schedule.split_share ?? schedule.clam_value })}
)}
{timeText && (expired ? (
@@ -1706,12 +1854,23 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
availableBonusChores.map(schedule => (
handleBonusCardContextMenu(e, schedule)}
+ onPointerDown={(e) => handleBonusCardPointerDown(e, schedule)}
+ onPointerMove={handleBonusCardPointerMove}
+ onPointerUp={handleBonusCardPointerEnd}
+ onPointerLeave={handleBonusCardPointerCancel}
+ onPointerCancel={handleBonusCardPointerCancel}
+ onClickCapture={handleBonusCardClickCapture}
sx={{
p: 1,
border: '1px solid var(--accent)',
borderRadius: 'var(--hg-radius-sm)',
mb: 1,
- bgcolor: 'rgba(var(--accent-rgb), 0.1)'
+ bgcolor: 'rgba(var(--accent-rgb), 0.1)',
+ // Keep a hold from triggering text selection / iOS callout.
+ userSelect: 'none',
+ WebkitUserSelect: 'none',
+ WebkitTouchCallout: 'none'
}}
>
@@ -2088,7 +2247,7 @@ const ChoreWidget = ({ refreshNonce = 0, hiddenControls = [] }) => {
anchorReference="anchorPosition"
anchorPosition={choreMenu.position || undefined}
>
- {!hideTransferChore && choreMenu.schedule?.transferable !== 0 && getTransferTargets(users, choreMenu.schedule?.user_id, '', choreMenu.schedule).length > 0 && (
+ {!hideTransferChore && choreMenu.schedule?.transferable !== 0 && !splitHasTickedShare(choreMenu.schedule, history) && getTransferTargets(users, choreMenu.schedule?.user_id, '', choreMenu.schedule).length > 0 && (