Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.

## Unreleased

- **OpenBot Mobile: four tabs, one place for notifications, and Account in the look of the other
tabs.** The tabs are Chats, Bots, Account and More. Notifications, in More, is everything that
waits on you: approvals and questions from your Bots, what their check-ins found, and the tasks
that wait, with the phone's switch for notifications at its top, which now turns them off too. It
replaces the approval inbox and the Needs you tab, and More's badge counts what is in it. More
opens a small menu above the tab bar, over the tab you are on: Material's own on Android.
Account is a list to the screen's edges: who is signed in, each organization with its letter and
a tick on the one you work in, then Sign out and Delete account. Swipe an organization to delete
it, if you own it, or to leave it. The Delete account and Delete organization sheets follow. A
list with nothing in it yet says so in the middle of the screen.
- **Delete your account from OpenBot Mobile.** Account, then Delete account: type your email address
and "delete my account". The account goes in 14 days, or at once with Delete now, as in the web
app. A sign-in older than ten minutes is asked for again first. Somebody who signs in again before
Expand Down
38 changes: 32 additions & 6 deletions docs/app-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,39 @@ Native's, and builds its own only when neither fits. The development build shows
security floor, the session and the version check have answered, and then the orb glides into
Welcome, or swells and fades into a signed-in screen. Nothing else draws a loading screen of its
own while the app opens.
- **The tabs** are the signed-in app's five, in the platform's tab bar, as icons with no words:
Chats, Bots (OpenBot's orb as a flat glyph), your Account in the middle, Needs you (its badge
counts what waits), and More (Routines, the approval inbox with a count of what waits there, Memory,
Skills and Connections). Each tab is a stack of its own with the native header, its title at the
- **The tabs** are the signed-in app's four, in the platform's tab bar, as icons with no words:
Chats, Bots (OpenBot's orb as a flat glyph), your Account, and More (Routines, Notifications,
Memory, Skills and Connections). More's badge counts what waits on the person, which
Notifications lists. Each tab is a stack of its own with the native header, its title at the
start of the bar. A conversation, a Bot and everything else opened from a tab open in the app's
stack over the tabs, so the tab bar steps aside and the message box has the bottom to itself;
what opens from More stays in More.
stack over the tabs, so the tab bar steps aside and the message box has the bottom to itself.
- **More is a menu.** The bar's last button opens a small menu above the bar, over the tab the
person is on, and what is picked opens in the app's stack. A tab that only held a list of five
links cost a screen and a second tap. On Android it is Material's own menu
(`mobile/src/more-menu.android.tsx`), as one surface with a line between its two parts:
Material's grouped menu draws two surfaces, and one casts its shadow onto the other. On iOS it is drawn by the app with the phone's own glass
and SF Symbols (`mobile/src/more-menu.tsx`), because iOS's own menu (`@expo/ui`'s `Menu`) always
opens over the button that opens it, so it covered the tab bar, and can't be hung from anything
else. Both read `mobile/src/more-items.ts`, and so does More as a screen, which opens where a
press reaches the tab itself.
- **Notifications is one place**, in More: the phone's switch for them, and under it everything
that waits on the person, by kind: approvals and questions from their Bots, what the Bots'
check-ins found, and the tasks that wait. It was the approval inbox and the Needs you tab. The
address `needs-you`, which a ping's notification opens, goes there.
- **A tab's own list runs to the screen's edges, with no card** (`ListRow`): Chats, Bots, and your
Account, where an organization is a row with its letter and the one worked in has the tick. A
card of rows with hairlines and icon tiles (`Rows`) is for a page of settings opened from one.
What a row is about shows in its shape: a person is a circle, a Bot its orb, an organization a
rounded square with its letter.
- **A row's own action is a swipe** (`SwipeRow`): the row slides left and one button, its glyph
alone, is in the room it leaves, as in the phone's own lists. A swipe alone never does it, and what deletes still asks
first. An organization on Account swipes for Delete (its owner) or Leave (anybody else).
- **An empty list says so in the middle of the screen** (`EmptyState`): a glyph, its name, a line or
two, and one button when the way on is right there. No box around it. A page (`ScrollScreen`) and a
tab's list (`ScreenList`) are as tall as what the bars leave, so it centers in what the person
sees and the empty page doesn't scroll.
- **The fade under the header is for what has scrolled under it.** A page at rest has none over its
own first lines.
- **Chats** is the word for conversations, everywhere a person reads it.
- **A chat** is headed as iMessage heads one: the orbs of the Bots in it and their names, and
tapping it opens the Bot's page, or a group's Bots. It reads from the top down, and opens at its
Expand Down
260 changes: 150 additions & 110 deletions mobile/app/(tabs)/(account)/account.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
import { router } from "expo-router";
import { useCallback, useEffect, useState } from "react";
import { View } from "react-native";
import { chooseOrganization, organizationChoices } from "../../../src/api";
import { router, useFocusEffect } from "expo-router";
import { Button } from "heroui-native/button";
import { useCallback, useState } from "react";
import { ActivityIndicator, Alert, View } from "react-native";
import { useCSSVariable } from "uniwind";
import {
chooseOrganization,
ME,
organizationChoices,
rereadOrganizations,
} from "../../../src/api";
import { removeOrganizationMember } from "../../../src/api/generated/organizations/organizations";
import { getAccountDeletion } from "../../../src/api/generated/people/people";
import { authClient, serverUrl } from "../../../src/auth";
import {
Icon,
ListRow,
Monogram,
Notice,
PersonAvatar,
Row,
Rows,
ScrollScreen,
Section,
type SwipeAction,
SwipeRow,
Text,
} from "../../../src/components";
import {
IconBell,
IconBuilding,
IconCheck,
IconLogout,
IconTrash,
} from "../../../src/icons";
import {
pushTurnedOn,
registerPush,
unregisterPush,
} from "../../../src/notifications";
import { IconCheck, IconLogout, IconTrash } from "../../../src/icons";
import { unregisterPush } from "../../../src/notifications";
import { type ListedOrganization, wayOut } from "../../../src/organization";
import { useLoad } from "../../../src/use-load";

/**
* Your account, a tab of its own: who is signed in, the organization they work in
* (and the others they can switch to), notifications on this phone, and signing out. It opens as a
* Bot's page does: the person, centered, then a card of rows for each part.
* Your account, a tab of its own: who is signed in, the organizations they can work in, and the two ways out.
*
* Everything starts on one line down the screen, as the other tabs' lists do, with no cards. Who is signed in
* is the first row. An organization is a row with its letter, and the one worked in has the tick: a tap works
* in another, and a swipe to the left is the way out of one (src/organization.ts), where its owner deletes it,
* anybody else leaves it, and the person's own has none. Sign out and Delete account are the two buttons at
* the foot, the second in the quieter red of what can't be taken back, and which OpenBot this is under them.
* Notifications are in More (app/approvals.tsx).
*/
export default function Account() {
const { data: session } = authClient.useSession();
const muted = useCSSVariable("--color-muted") as string | undefined;
const [busy, setBusy] = useState("");
const [error, setError] = useState("");
const [pushRegistered, setPushRegistered] = useState(false);
// Said as it is on this phone, not as it was before the app last started.
useEffect(() => {
void pushTurnedOn()
.then(setPushRegistered)
.catch(() => {});
}, []);
const loadOrganizations = useCallback(() => organizationChoices(), []);
// The person's own list, whichever organization they work in: it stays on screen while it is read again.
const organizations = useLoad(loadOrganizations, Boolean(session), {
keep: true,
});
// Deleting the account is offered where this OpenBot has it: one that answers where the deletion stands.
// The person's own too, so the line stays while it is read again.
// The person's own too, so the button stays while it is read again.
const loadDeletion = useCallback(() => getAccountDeletion(), []);
const deletion = useLoad(loadDeletion, Boolean(session), { keep: true });
// Read again each time the tab comes back: an organization deleted in the sheet over it is gone from the list.
const rereadList = organizations.refresh;
useFocusEffect(
useCallback(() => {
void rereadList();
}, [rereadList]),
);
async function act(name: string, work: () => Promise<unknown>) {
setBusy(name);
setError("");
Expand All @@ -68,43 +74,110 @@ export default function Account() {
setBusy("");
}
}
/** What a row offers when it is swiped: the way out of that organization, asked about before it is done. */
function swipe(organization: ListedOrganization): SwipeAction | undefined {
const name = organization.name ?? organization.id;
const way = wayOut(organization);
if (way === "delete")
return {
label: `Delete ${name}`,
icon: IconTrash,
tone: "danger",
// The sheet says what goes with it, and waits for its name to be typed.
onPress: () =>
router.push({
pathname: "/delete-organization",
params: { id: organization.id, name },
}),
};
if (way === "leave")
return {
label: `Leave ${name}`,
icon: IconLogout,
onPress: () =>
Alert.alert(
`Leave ${name}?`,
"You stop being a member. What you made there stays there.",
[
{ text: "Cancel", style: "cancel" },
{
text: "Leave",
style: "destructive",
onPress: () =>
void act(organization.id, async () => {
await removeOrganizationMember(organization.id, ME);
await rereadOrganizations();
await organizations.refresh();
}),
},
],
),
};
return undefined;
}
const person = session?.user.name || session?.user.email || "";
const listed = organizations.data?.organizations ?? [];
// The OpenBot this phone is signed in to, as its address reads without the scheme.
const server = serverUrl.replace(/^https?:\/\//, "").replace(/\/$/, "");
return (
<ScrollScreen>
<View className="items-center gap-3">
<PersonAvatar name={person} size={64} />
<View className="items-center gap-1">
<Text variant="heading" className="text-center">
<ScrollScreen className="gap-0 px-0 pt-5">
<View className="flex-row items-center gap-4 px-4">
<PersonAvatar name={person} size={60} />
<View className="flex-1 gap-0.5">
<Text variant="heading" numberOfLines={1} className="text-xl">
{person}
</Text>
{session?.user.name && session.user.email ? (
<Text tone="muted" className="text-center text-sm">
<Text tone="muted" numberOfLines={1}>
{session.user.email}
</Text>
) : null}
</View>
</View>
<Notice message={error || organizations.error} />
{error || organizations.error ? (
<View className="px-4 pt-5">
<Notice message={error || organizations.error} />
</View>
) : null}
{listed.length > 0 ? (
<Section title={listed.length > 1 ? "Organizations" : "Organization"}>
<Rows>
{listed.map((organization) => {
const current = organization.id === organizations.data?.currentId;
return (
<Row
key={organization.id}
icon={IconBuilding}
title={organization.name ?? organization.id}
description={current ? "You're working here" : undefined}
<>
<Text
variant="caption"
tone="muted"
accessibilityRole="header"
className="px-4 pt-8 pb-1.5 font-medium"
>
{listed.length > 1 ? "Organizations" : "Organization"}
</Text>
{listed.map((organization) => {
const current = organization.id === organizations.data?.currentId;
const name = organization.name ?? organization.id;
return (
<SwipeRow
key={organization.id}
action={swipe(organization)}
disabled={Boolean(busy)}
>
<ListRow
leading={<Monogram name={name} />}
title={name}
accessibilityLabel={
current ? `${name}, you're working here` : `Work in ${name}`
}
accessibilityState={{
selected: current,
busy: busy === organization.id,
}}
trailing={
current ? <Icon icon={IconCheck} size={18} /> : undefined
busy === organization.id ? (
<ActivityIndicator color={muted} />
) : current ? (
<Icon icon={IconCheck} size={20} />
) : undefined
}
chevron={false}
disabled={Boolean(busy)}
onPress={
current || busy
current
? undefined
: () =>
void act(organization.id, async () => {
Expand All @@ -117,70 +190,37 @@ export default function Account() {
})
}
/>
);
})}
</Rows>
</Section>
</SwipeRow>
);
})}
</>
) : null}
<Section title="This phone">
<Rows>
<Row
icon={IconBell}
title="Notifications"
description={
pushRegistered
? "On. Bots can tell you when they finish or need you."
: "Get told when a Bot finishes or needs you."
}
trailing={
pushRegistered ? (
<Icon icon={IconCheck} size={18} />
) : (
<Text variant="caption" className="font-medium">
Turn on
</Text>
)
}
chevron={false}
onPress={
pushRegistered || busy
? undefined
: () =>
void act("push", async () => {
await registerPush();
setPushRegistered(true);
})
}
/>
</Rows>
</Section>
<Rows>
<Row
icon={IconLogout}
title="Sign out"
description={`Signed in to ${server}`}
tone="danger"
chevron={false}
onPress={
busy
? undefined
: () =>
void act("sign-out", async () => {
await unregisterPush();
await authClient.signOut();
})
<View className="gap-2.5 px-4 pt-8">
<Button
variant="secondary"
isDisabled={Boolean(busy)}
onPress={() =>
void act("sign-out", async () => {
await unregisterPush();
await authClient.signOut();
})
}
/>
>
{busy === "sign-out" ? "Signing out…" : "Sign out"}
</Button>
{deletion.data ? (
<Row
icon={IconTrash}
title="Delete account"
description="Delete your account and everything that's only yours."
tone="danger"
onPress={busy ? undefined : () => router.push("/delete-account")}
/>
<Button
variant="danger-soft"
isDisabled={Boolean(busy)}
onPress={() => router.push("/delete-account")}
>
Delete account
</Button>
) : null}
</Rows>
<Text variant="caption" tone="muted" className="pt-1.5 text-center">
{`Signed in to ${server}`}
</Text>
</View>
</ScrollScreen>
);
}
Loading
Loading