SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

saveStatusSync

Why JS.

tsx
import { saveStatusSync } from "@sdxc/ui/app";

Usage

Applied to a save status ([data-slot="save-status"]): "Saving…" holds for holdMs however fast the save, "Saved" shows for savedMs, then the edit time shows and keeps its age current. It writes data-state and the texts of its save-status-* parts.

Signature

typescript
saveStatusSync(options: SaveStatusSync.Options): MixinDescriptor<HTMLElement>

Parameters

ParameterTypeRequiredDescription
optionsSaveStatusSync.OptionsYes

Examples

tsx
<span data-slot="save-status" mix={[saveStatusSync({ state: "idle", labels, holdMs: 1000, savedMs: 3000, decayMs: 86_400_000 })]}>…</span>

The events, constants and types its module publishes, each imported from @sdxc/ui/app too.

Event

SaveStatusEvent

Reports a save to a save status: dispatched on it by setSaveStatus.

typescript
new SaveStatusEvent(state: SaveStatusSync.State, at?: Date)
PropertyTypeRequiredDescription
statereadonly SaveStatusSync.StateYes
atreadonly Date | undefinedYesWhen the content was saved; the moment the event arrives when omitted.
Event

SaveStatusRetryEvent

Dispatched, bubbling, from a save status when its Retry is pressed, for an autosave to try again.

typescript
new SaveStatusRetryEvent()
Function

setSaveStatus

Reports a save to a save status, which is how an autosave drives it.

typescript
setSaveStatus(target: Element | string, state: SaveStatusSync.State, at?: Date): void
ParameterTypeRequiredDescription
targetElement | stringYesThe status element or its id.
stateSaveStatusSync.StateYesWhere the save stands.
atDateNoWhen the content was saved.
tsx
setSaveStatus("post-status", "saving");
let response = await fetch(url, { method: "POST", body });
setSaveStatus("post-status", response.ok ? "saved" : "failed");
Interface

SaveStatusSync.Options

Configuration for saveStatusSync.

MemberTypeRequiredDescription
stateStateYesThe state the server rendered.
editedAtstringNoWhen the content was last edited, as an ISO string.
labels{ saving: string; saved: string; failed: string; edited: string }Yes
localestringNo
holdMsnumberYes
savedMsnumberYes
decayMsnumberYes
Type

SaveStatusSync.State

Where a save stands; "idle" shows the last edit time, or nothing without one.

typescript
type SaveStatusSync.State = "idle" | "saving" | "saved" | "failed"
@sdxc/ui

Can’t find it? Contact us