Use shared modals and combine selected-day actions
This commit is contained in:
@@ -172,6 +172,7 @@ function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => voi
|
||||
const [archive, setArchive] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [needsRefresh, setNeedsRefresh] = useState(false);
|
||||
const focusAddAfterRefresh = useRef(false);
|
||||
const saving = useRef(false);
|
||||
const mounted = useRef(true);
|
||||
const expired = useRef(onExpired);
|
||||
@@ -207,7 +208,13 @@ function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => voi
|
||||
if (!controller.signal.aborted) reportError(error);
|
||||
})
|
||||
.finally(() => {
|
||||
if (!controller.signal.aborted) setLoading(false);
|
||||
if (!controller.signal.aborted) {
|
||||
setLoading(false);
|
||||
if (focusAddAfterRefresh.current) {
|
||||
focusAddAfterRefresh.current = false;
|
||||
window.requestAnimationFrame(() => document.getElementById("add-habit")?.focus({ preventScroll: true }));
|
||||
}
|
||||
}
|
||||
});
|
||||
return () => controller.abort();
|
||||
}, [attempt, reportError]);
|
||||
@@ -361,6 +368,7 @@ function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => voi
|
||||
<div className="ds-action-row ds-primary-actions">
|
||||
<Button
|
||||
id="add-habit"
|
||||
aria-haspopup="dialog"
|
||||
disabled={adding || busy || loading || needsRefresh}
|
||||
onClick={() => setAdding(true)}
|
||||
aria-expanded={adding}
|
||||
@@ -370,14 +378,14 @@ function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => voi
|
||||
</Button>
|
||||
{today.habits.length > 0 && (
|
||||
<>
|
||||
<Button id="open-sharing" variant="secondary" disabled={busy || loading || needsRefresh || sharing} aria-expanded={sharing} aria-controls={sharing ? "share-progress" : undefined} onClick={() => setSharing(true)}>Share progress</Button>
|
||||
<Button id="open-sharing" aria-haspopup="dialog" variant="secondary" disabled={busy || loading || needsRefresh || sharing} aria-expanded={sharing} aria-controls={sharing ? "share-progress" : undefined} onClick={() => setSharing(true)}>Share progress</Button>
|
||||
<ButtonLink href="#habits-title">View your habits ↓</ButtonLink>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="ds-action-row ds-utility-row">
|
||||
<Button variant="text" disabled={busy} aria-expanded={archive} aria-controls={archive ? "archived-habits" : undefined} onClick={() => setArchive(!archive)}><Archive size={16} aria-hidden="true" />Archived habits</Button>
|
||||
<Button variant="text" disabled={busy} aria-expanded={settings} aria-controls={settings ? "account-settings" : undefined} onClick={() => setSettings(!settings)}><Settings2 size={16} aria-hidden="true" />Settings</Button>
|
||||
<Button variant="text" disabled={busy} aria-haspopup="dialog" aria-expanded={archive} aria-controls={archive ? "archived-habits" : undefined} onClick={() => setArchive(!archive)}><Archive size={16} aria-hidden="true" />Archived habits</Button>
|
||||
<Button variant="text" disabled={busy} aria-haspopup="dialog" aria-expanded={settings} aria-controls={settings ? "account-settings" : undefined} onClick={() => setSettings(!settings)}><Settings2 size={16} aria-hidden="true" />Settings</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
@@ -410,6 +418,7 @@ function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => voi
|
||||
onCancel={() => setAdding(false)}
|
||||
onExpired={() => expired.current()}
|
||||
onCreated={(name) => {
|
||||
focusAddAfterRefresh.current = true;
|
||||
setAdding(false);
|
||||
setNotice(`${name} created.`);
|
||||
setAttempt((value) => value + 1);
|
||||
@@ -536,7 +545,7 @@ function SavedHabit({
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{addingTask ? (
|
||||
{addingTask && (
|
||||
<InlineTaskEditor
|
||||
name=""
|
||||
schedule={{ type: "daily" }}
|
||||
@@ -549,20 +558,21 @@ function SavedHabit({
|
||||
onSave={(patch) => onManage(habit, patch, undefined, true)}
|
||||
onDelete={async () => {}}
|
||||
/>
|
||||
) : (
|
||||
)}
|
||||
<div className="ds-task-add-action">
|
||||
{!habit.requirements.tasks.length && (
|
||||
<p className="ds-footnote">Add a task to start checking in.</p>
|
||||
)}
|
||||
<Button
|
||||
variant="text"
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={addingTask}
|
||||
disabled={disabled || habit.requirements.tasks.length >= 100}
|
||||
onClick={() => setAddingTask(true)}
|
||||
>
|
||||
Add task +
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user