mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
feat(native): swipe rows, long-press menus, placeholders while loading, fading pictures, iOS bounce and app icon quick actions
Packing items, tasks and expenses swipe sideways to their actions, as in Mail or Reminders: done or open one way, delete and edit the other, the first one run by a full swipe. They are second ways to what each row already offers; an expense still asks before it goes. A long press on a trip card lifts it and opens its menu with the card's own actions. Plain confirmations in MConfirmSheet now also ask through the system where the app can. Lists, the atlas and a journey show grey placeholders in their shape while loading instead of a spinner in an empty screen (MSkeleton); buttons keep theirs. A picture still loading fades in once it is there; one from the cache shows at once. In the iOS app the page bounces at its ends again, except on screens with pull-to-refresh, whose pull it would race; Android keeps its stretch off. On iOS a long press on the app icon offers "New trip" and the trip coming up by its name, set by the UI in its language (TrekShell.setQuickActions, feature quickActions), and a tap opens it, also from a cold start. The app's own CSS moves out of index.css into native/nativeApp.css, which had outgrown its size budget.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* NativeQuickActionsSync: keeps the app icon's quick actions (native/quickActions.ts)
|
||||
* in step with the trips on this device and the app's language. Runs at start,
|
||||
* on a change of language or account, and whenever the app comes back to the
|
||||
* foreground. Signed out, the icon offers nothing that would open a trip.
|
||||
* Renders nothing; outside an iOS binary with the feature it does nothing.
|
||||
*/
|
||||
import { App } from '@capacitor/app';
|
||||
import { useEffect } from 'react';
|
||||
import { offlineDb } from '../../db/offlineDb';
|
||||
import { useTranslation } from '../../i18n';
|
||||
import { useNativeCapabilities } from '../../native/capabilities';
|
||||
import { publishQuickActions, quickActionsActive, quickActionsFor } from '../../native/quickActions';
|
||||
import { pickTrip } from '../../native/widgets';
|
||||
import { useAuthStore } from '../../store/authStore';
|
||||
import { localDateStr } from '../../vacay/monthGrid';
|
||||
|
||||
export default function NativeQuickActionsSync() {
|
||||
const { t, language } = useTranslation();
|
||||
const { caps } = useNativeCapabilities();
|
||||
const userId = useAuthStore((s) => (s.isAuthenticated ? (s.user?.id ?? null) : null));
|
||||
|
||||
useEffect(() => {
|
||||
if (!quickActionsActive()) return;
|
||||
let cancelled = false;
|
||||
|
||||
const sync = async () => {
|
||||
if (userId === null) {
|
||||
await publishQuickActions([]);
|
||||
return;
|
||||
}
|
||||
const now = new Date();
|
||||
const today = localDateStr(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
const trips = await offlineDb.trips.toArray();
|
||||
if (cancelled) return;
|
||||
await publishQuickActions(quickActionsFor(pickTrip(trips, today), today, t));
|
||||
};
|
||||
|
||||
void sync();
|
||||
const listener = App.addListener('appStateChange', ({ isActive }) => {
|
||||
if (isActive) void sync();
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
void listener.then((handle) => handle.remove());
|
||||
};
|
||||
}, [caps, t, language, userId]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user