Skip to content
150 changes: 48 additions & 102 deletions app/components/SearchOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2026 Cloudhal and the Podbay contributors
// Licensed under the Apache 2.0 license found in the LICENSE file.

import { Input, LayerDialog } from "@cloudflare/kumo";
import { Checkbox, Input, LayerDialog, Select } from "@cloudflare/kumo";
import { type FormEvent, useEffect, useState } from "react";
import DateTimeField from "~/components/controls/DateTimeField";
import { t } from "~/i18n";
import { placeName } from "~/lib/places";
import {
Expand All @@ -15,9 +16,6 @@ import { useFolders } from "~/queries/folders";
import { useLabels } from "~/queries/labels";
import type { Folder } from "~/types";

const NATIVE_FIELD =
"h-9 w-full rounded-lg border border-kumo-line bg-kumo-control px-3 text-sm text-kumo-default";

/**
* A search by its parts: who, what, where and when. It writes the same query a person could type
* in the search box, so the box always shows what is being searched.
Expand Down Expand Up @@ -61,126 +59,74 @@ export default function SearchOptions({
<LayerDialog.Body>
<form id="search-options" onSubmit={submit} className="space-y-3">
<Input
size="sm"
label={t("From")}
value={options.from}
onChange={(event) => set({ from: event.target.value })}
/>
<Input
size="sm"
label={t("To")}
value={options.to}
onChange={(event) => set({ to: event.target.value })}
/>
<Input
size="sm"
label={t("Subject")}
value={options.subject}
onChange={(event) => set({ subject: event.target.value })}
/>
<Input
size="sm"
label={t("Has the words")}
value={options.words}
onChange={(event) => set({ words: event.target.value })}
/>
<div>
<label
htmlFor="search-label"
className="mb-1.5 block text-sm font-medium text-kumo-default"
>
{t("Label")}
</label>
<select
id="search-label"
className={NATIVE_FIELD}
value={options.label}
onChange={(event) => set({ label: event.target.value })}
>
<option value="">{t("Any")}</option>
{/* A label the box names that no longer exists is still shown, so it is not lost silently */}
{options.label !== "" && !labels.some((l) => l.name === options.label) && (
<option value={options.label}>{options.label}</option>
)}
{labels.map((label) => (
<option key={label.id} value={label.name}>
{label.name}
</option>
))}
</select>
</div>
<Select
label={t("Label")}
className="w-full"
value={options.label}
onValueChange={(label) => set({ label: String(label ?? "") })}
items={[
{ label: t("Any"), value: "" },
// A label the box names that no longer exists is still shown, so it is not lost silently
...(options.label !== "" && !labels.some((l) => l.name === options.label)
? [{ label: options.label, value: options.label }]
: []),
...labels.map((label) => ({ label: label.name, value: label.name })),
]}
/>
<div className="grid grid-cols-1 gap-3 sm:grid-cols-3">
<div>
<label
htmlFor="search-in"
className="mb-1.5 block text-sm font-medium text-kumo-default"
>
{t("Search in")}
</label>
<select
id="search-in"
className={NATIVE_FIELD}
value={options.folder}
onChange={(event) => set({ folder: event.target.value })}
>
<option value="">{t("All mail")}</option>
{folders.map((folder) => (
<option key={folder.id} value={folder.id}>
{placeName(folder.id)}
</option>
))}
</select>
</div>
<div>
<label
htmlFor="search-after"
className="mb-1.5 block text-sm font-medium text-kumo-default"
>
{t("After")}
</label>
<input
id="search-after"
type="date"
className={NATIVE_FIELD}
value={options.after}
onChange={(event) => set({ after: event.target.value })}
/>
</div>
<div>
<label
htmlFor="search-before"
className="mb-1.5 block text-sm font-medium text-kumo-default"
>
{t("Before")}
</label>
<input
id="search-before"
type="date"
className={NATIVE_FIELD}
value={options.before}
onChange={(event) => set({ before: event.target.value })}
/>
</div>
<Select
label={t("Search in")}
className="w-full"
value={options.folder}
onValueChange={(folder) => set({ folder: String(folder ?? "") })}
items={[
{ label: t("All mail"), value: "" },
...folders.map((folder) => ({ label: placeName(folder.id), value: folder.id })),
]}
/>
<DateTimeField
kind="date"
label={t("After")}
value={options.after}
onChange={(after) => set({ after })}
/>
<DateTimeField
kind="date"
label={t("Before")}
value={options.before}
onChange={(before) => set({ before })}
/>
</div>
<div className="flex flex-wrap gap-x-6 gap-y-2 pt-1">
<label className="flex items-center gap-2 text-sm text-kumo-default">
<input
type="checkbox"
className="h-4 w-4"
checked={options.hasAttachment}
onChange={(event) => set({ hasAttachment: event.target.checked })}
/>
{t("Has an attachment")}
</label>
<label className="flex items-center gap-2 text-sm text-kumo-default">
<input
type="checkbox"
className="h-4 w-4"
checked={options.unreadOnly}
onChange={(event) => set({ unreadOnly: event.target.checked })}
/>
{t("Unread only")}
</label>
<Checkbox
label={t("Has an attachment")}
checked={options.hasAttachment}
onCheckedChange={(checked) => set({ hasAttachment: checked === true })}
/>
<Checkbox
label={t("Unread only")}
checked={options.unreadOnly}
onCheckedChange={(checked) => set({ unreadOnly: checked === true })}
/>
</div>
</form>
</LayerDialog.Body>
Expand Down
30 changes: 9 additions & 21 deletions app/components/SendLater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { Button, DropdownMenu, LayerDialog } from "@cloudflare/kumo";
import { CalendarBlankIcon, ClockIcon } from "@phosphor-icons/react";
import { type FormEvent, useState } from "react";
import { SENDING } from "shared/sending";
import DateTimeField from "~/components/controls/DateTimeField";
import { t } from "~/i18n";
import { fieldValue, laterChoices, timeRefusal, timeWords } from "~/lib/sending-words";

const NATIVE_FIELD =
"h-9 w-full rounded-lg border border-kumo-line bg-kumo-control px-3 text-sm text-kumo-default";

/**
* "Send later" (ADR-0016, decision 12): a few times of the app's own and a date and time, in
* this device's time zone. Every choice is shown back with its date and time before it is
Expand Down Expand Up @@ -108,24 +106,14 @@ export default function SendLater({
onInput={(event) => event.stopPropagation()}
>
<form id="send-later" onSubmit={choose} className="space-y-3">
<div>
<label
htmlFor="send-later-time"
className="mb-1.5 block text-sm font-medium text-kumo-default"
>
{t("Date and time")}
</label>
<input
id="send-later-time"
type="datetime-local"
className={NATIVE_FIELD}
value={picked}
min={fieldValue(now)}
max={fieldValue(new Date(now.getTime() + SENDING.farthestMs))}
onChange={(event) => setPicked(event.target.value)}
required
/>
</div>
<DateTimeField
label={t("Date and time")}
value={picked}
min={fieldValue(now)}
max={fieldValue(new Date(now.getTime() + SENDING.farthestMs))}
onChange={setPicked}
required
/>
{refusal === null && picked !== "" ? (
<p className="m-0 text-sm text-kumo-default">
{t("The message will be sent {time}.", { time: timeWords(time) })}
Expand Down
54 changes: 54 additions & 0 deletions app/components/controls/DateTimeField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2026 Cloudhal and the Podbay contributors
// Licensed under the Apache 2.0 license found in the LICENSE file.

import { Label } from "@cloudflare/kumo";
import { useId } from "react";

/**
* A date, or a date with a time of day, as a person types or picks it: the one place the app
* uses the browser's own date field (issue #82). Kumo 2.18.1 has no field for a date and a time:
* its DatePicker is a calendar with no time of day and no field to type in.
*
* The field is drawn once, here, at the height, corner and type of Kumo's default size (36 px,
* 14 px), with Kumo's label above it, so it stands beside Kumo's fields as one of them. The label
* stands where a Kumo select draws its own: a line of its own type above the field, 8 px apart, so
* a row of selects and date fields shares its labels' top as well as its fields'. Its
* limit stays: the browser shows the date in the device's own form and language, not the app's.
*/
export default function DateTimeField({
label,
kind = "datetime-local",
labelClassName,
...field
}: {
/** What the field is called; it is its label above it. */
label: string;
/** A date alone, or a date with a time of day. */
kind?: "date" | "datetime-local";
/** The label's own look where a screen sets labels apart, as a small subtle line. */
labelClassName?: string;
value: string;
onChange: (value: string) => void;
min?: string;
max?: string;
required?: boolean;
}) {
const id = useId();
const { onChange, ...rest } = field;
return (
<div className="grid gap-2">
<div className={labelClassName ?? "text-base"}>
<Label htmlFor={id} className={labelClassName}>
{label}
</Label>
</div>
<input
{...rest}
id={id}
type={kind}
className="h-9 w-full rounded-lg border border-kumo-line bg-kumo-control px-3 text-base text-kumo-default"
onChange={(event) => onChange(event.target.value)}
/>
</div>
);
}
Loading