Compare commits
7 Commits
luggage-li
...
luggage-li
| Author | SHA1 | Date | |
|---|---|---|---|
| d33fecd657 | |||
| 2417d2d597 | |||
| f28ff010d7 | |||
| d40bd6a41c | |||
| 2e45261354 | |||
| bd500674a0 | |||
| ef7e0ba7a1 |
2
TODO.md
2
TODO.md
@@ -37,3 +37,5 @@ Improving & Fixing Bugs (V3)
|
||||
- [x] Increased safe top inset to avoid status-bar overlap
|
||||
- [x] Added check-up stats (correct/bad/pending) and persisted per snapshot
|
||||
- [x] Extra UI polish pass (spacing, cards, hierarchy)
|
||||
- [x] Centered and enlarged edit/check-up modals to fully overlay nav
|
||||
- [x] Fixed modal keyboard glitching (stable centered keyboard-aware layout)
|
||||
|
||||
11
app.json
11
app.json
@@ -34,6 +34,15 @@
|
||||
"eas": {
|
||||
"projectId": "1275f90e-33c6-4af1-942e-ca29a309f8c8"
|
||||
}
|
||||
}
|
||||
},
|
||||
"plugins": [
|
||||
[
|
||||
"expo-image-picker",
|
||||
{
|
||||
"photosPermission": "Allow Luggage List to access your photos for trip and item images.",
|
||||
"cameraPermission": "Allow Luggage List to use your camera to take trip and item photos."
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
320
src/AppRoot.js
320
src/AppRoot.js
@@ -7,13 +7,13 @@ import BottomTab from './components/BottomTab';
|
||||
import TripPicker from './components/TripPicker';
|
||||
import DatePickerModal from './components/DatePickerModal';
|
||||
import ItemModal from './modals/ItemModal';
|
||||
import CheckupFixModal from './modals/CheckupFixModal';
|
||||
import CheckupFlowModal from './modals/CheckupFlowModal';
|
||||
import TripsTab from './tabs/TripsTab';
|
||||
import ItemsTab from './tabs/ItemsTab';
|
||||
import CheckupTab from './tabs/CheckupTab';
|
||||
import HistoryTab from './tabs/HistoryTab';
|
||||
import { emptyData, STORAGE_KEY } from './constants';
|
||||
import { findActiveTripId, makeId, parseYMD, todayYMD } from './utils/date';
|
||||
import { findBestTripId, makeId, parseYMD, todayYMD } from './utils/date';
|
||||
import { styles } from './styles';
|
||||
|
||||
const emptyTripForm = () => ({
|
||||
@@ -37,6 +37,28 @@ const emptyItemForm = () => ({
|
||||
imageUri: '',
|
||||
});
|
||||
|
||||
const emptyCheckupNoForm = () => ({
|
||||
status: 'unpacked',
|
||||
placement: 'suitcase',
|
||||
lentTo: '',
|
||||
updateMasterList: false,
|
||||
});
|
||||
|
||||
function buildCheckupSession(items) {
|
||||
return items.map((item) => ({
|
||||
itemId: item.id,
|
||||
name: item.name,
|
||||
category: item.category,
|
||||
current: {
|
||||
status: item.status,
|
||||
placement: item.placement,
|
||||
lentTo: item.lentTo || '',
|
||||
},
|
||||
confirmed: false,
|
||||
result: 'pending',
|
||||
}));
|
||||
}
|
||||
|
||||
export default function AppRoot() {
|
||||
const scrollRef = useRef(null);
|
||||
|
||||
@@ -52,14 +74,10 @@ export default function AppRoot() {
|
||||
const [itemForm, setItemForm] = useState(emptyItemForm());
|
||||
|
||||
const [checkupSession, setCheckupSession] = useState([]);
|
||||
const [checkupFixModalVisible, setCheckupFixModalVisible] = useState(false);
|
||||
const [checkupFixTargetId, setCheckupFixTargetId] = useState(null);
|
||||
const [checkupFixForm, setCheckupFixForm] = useState({
|
||||
status: 'unpacked',
|
||||
placement: 'suitcase',
|
||||
lentTo: '',
|
||||
updateMasterList: false,
|
||||
});
|
||||
const [checkupFlowVisible, setCheckupFlowVisible] = useState(false);
|
||||
const [checkupFlowIndex, setCheckupFlowIndex] = useState(0);
|
||||
const [checkupFlowMode, setCheckupFlowMode] = useState('question');
|
||||
const [checkupNoForm, setCheckupNoForm] = useState(emptyCheckupNoForm());
|
||||
|
||||
const [selectedCheckupId, setSelectedCheckupId] = useState(null);
|
||||
|
||||
@@ -90,6 +108,12 @@ export default function AppRoot() {
|
||||
return { total, correct, bad, pending };
|
||||
}, [checkupSession]);
|
||||
|
||||
const checkupCurrentEntry = useMemo(() => {
|
||||
if (!checkupFlowVisible) return null;
|
||||
if (checkupFlowIndex >= checkupSession.length) return null;
|
||||
return checkupSession[checkupFlowIndex] || null;
|
||||
}, [checkupFlowVisible, checkupFlowIndex, checkupSession]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
@@ -124,8 +148,8 @@ export default function AppRoot() {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeTripId = findActiveTripId(data.trips);
|
||||
setSelectedTripId(activeTripId || data.trips[0].id);
|
||||
const bestTripId = findBestTripId(data.trips);
|
||||
setSelectedTripId(bestTripId || data.trips[0].id);
|
||||
}, [data.trips, selectedTripId, loaded]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -169,10 +193,27 @@ export default function AppRoot() {
|
||||
}
|
||||
}
|
||||
|
||||
async function takeImage(onPicked) {
|
||||
const perm = await ImagePicker.requestCameraPermissionsAsync();
|
||||
if (!perm.granted) {
|
||||
Alert.alert('Permission needed', 'Allow camera access to take photos.');
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await ImagePicker.launchCameraAsync({
|
||||
allowsEditing: false,
|
||||
quality: 0.85,
|
||||
});
|
||||
|
||||
if (!result.canceled && result.assets?.[0]?.uri) {
|
||||
onPicked(result.assets[0].uri);
|
||||
}
|
||||
}
|
||||
|
||||
function createTrip() {
|
||||
if (!tripForm.name.trim()) {
|
||||
Alert.alert('Missing name', 'Trip name is required.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const start = parseYMD(tripForm.startDate);
|
||||
@@ -180,12 +221,12 @@ export default function AppRoot() {
|
||||
|
||||
if (!start || !end) {
|
||||
Alert.alert('Invalid dates', 'Please select valid trip dates.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (start > end) {
|
||||
Alert.alert('Invalid dates', 'Start date cannot be after end date.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
@@ -230,6 +271,7 @@ export default function AppRoot() {
|
||||
|
||||
setSelectedTripId(tripId);
|
||||
setTripForm(emptyTripForm());
|
||||
return true;
|
||||
}
|
||||
|
||||
function setTripAsTemplate(tripId) {
|
||||
@@ -341,72 +383,8 @@ export default function AppRoot() {
|
||||
});
|
||||
}
|
||||
|
||||
function createFreshCheckupSession() {
|
||||
if (!selectedTripItems.length) {
|
||||
setCheckupSession([]);
|
||||
return;
|
||||
}
|
||||
|
||||
const fresh = selectedTripItems.map((item) => ({
|
||||
itemId: item.id,
|
||||
name: item.name,
|
||||
category: item.category,
|
||||
current: {
|
||||
status: item.status,
|
||||
placement: item.placement,
|
||||
lentTo: item.lentTo || '',
|
||||
},
|
||||
confirmed: false,
|
||||
result: 'pending',
|
||||
}));
|
||||
|
||||
setCheckupSession(fresh);
|
||||
}
|
||||
|
||||
function answerCheckupYes(itemId) {
|
||||
setCheckupSession((prev) =>
|
||||
prev.map((entry) => (entry.itemId === itemId ? { ...entry, confirmed: true, result: 'correct' } : entry))
|
||||
);
|
||||
}
|
||||
|
||||
function openFixModal(itemId) {
|
||||
const entry = checkupSession.find((x) => x.itemId === itemId);
|
||||
if (!entry) return;
|
||||
|
||||
setCheckupFixTargetId(itemId);
|
||||
setCheckupFixForm({
|
||||
status: entry.current.status || 'unpacked',
|
||||
placement: entry.current.placement || 'suitcase',
|
||||
lentTo: entry.current.lentTo || '',
|
||||
updateMasterList: false,
|
||||
});
|
||||
setCheckupFixModalVisible(true);
|
||||
}
|
||||
|
||||
function saveFixModal() {
|
||||
if (!checkupFixTargetId) return;
|
||||
|
||||
const targetId = checkupFixTargetId;
|
||||
const patch = {
|
||||
status: checkupFixForm.status,
|
||||
placement: checkupFixForm.placement,
|
||||
lentTo: checkupFixForm.status === 'lent-to' ? checkupFixForm.lentTo.trim() : '',
|
||||
};
|
||||
|
||||
setCheckupSession((prev) =>
|
||||
prev.map((entry) =>
|
||||
entry.itemId === targetId
|
||||
? {
|
||||
...entry,
|
||||
current: patch,
|
||||
confirmed: true,
|
||||
result: 'bad',
|
||||
}
|
||||
: entry
|
||||
)
|
||||
);
|
||||
|
||||
if (checkupFixForm.updateMasterList && selectedTripId) {
|
||||
function quickSetItemStatus(itemId, status) {
|
||||
if (!selectedTripId) return;
|
||||
setData((prev) => {
|
||||
const items = prev.itemsByTrip[selectedTripId] || [];
|
||||
return {
|
||||
@@ -414,7 +392,127 @@ export default function AppRoot() {
|
||||
itemsByTrip: {
|
||||
...prev.itemsByTrip,
|
||||
[selectedTripId]: items.map((item) =>
|
||||
item.id === targetId
|
||||
item.id === itemId
|
||||
? {
|
||||
...item,
|
||||
status,
|
||||
lentTo: status === 'lent-to' ? item.lentTo : '',
|
||||
updatedAt: Date.now(),
|
||||
}
|
||||
: item
|
||||
),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function deleteCheckup(checkupId) {
|
||||
if (!selectedTripId) return;
|
||||
setData((prev) => {
|
||||
const existing = prev.checkupsByTrip[selectedTripId] || [];
|
||||
return {
|
||||
...prev,
|
||||
checkupsByTrip: {
|
||||
...prev.checkupsByTrip,
|
||||
[selectedTripId]: existing.filter((checkup) => checkup.id !== checkupId),
|
||||
},
|
||||
};
|
||||
});
|
||||
setSelectedCheckupId((prev) => (prev === checkupId ? null : prev));
|
||||
}
|
||||
|
||||
function createFreshCheckupSession() {
|
||||
if (!selectedTripItems.length) {
|
||||
setCheckupSession([]);
|
||||
return;
|
||||
}
|
||||
setCheckupSession(buildCheckupSession(selectedTripItems));
|
||||
}
|
||||
|
||||
function startCheckupFlow() {
|
||||
if (!selectedTripId) {
|
||||
Alert.alert('No trip selected', 'Please select a trip first.');
|
||||
return;
|
||||
}
|
||||
if (!selectedTripItems.length) {
|
||||
Alert.alert('No items', 'Add items before starting a check-up.');
|
||||
return;
|
||||
}
|
||||
|
||||
const fresh = buildCheckupSession(selectedTripItems);
|
||||
setCheckupSession(fresh);
|
||||
setCheckupFlowIndex(0);
|
||||
setCheckupFlowMode('question');
|
||||
setCheckupNoForm(emptyCheckupNoForm());
|
||||
setCheckupFlowVisible(true);
|
||||
}
|
||||
|
||||
function closeCheckupFlow() {
|
||||
setCheckupFlowVisible(false);
|
||||
setCheckupFlowMode('question');
|
||||
setCheckupNoForm(emptyCheckupNoForm());
|
||||
}
|
||||
|
||||
function goNextInCheckup() {
|
||||
setCheckupFlowIndex((prev) => prev + 1);
|
||||
setCheckupFlowMode('question');
|
||||
setCheckupNoForm(emptyCheckupNoForm());
|
||||
}
|
||||
|
||||
function answerCurrentCheckupYes() {
|
||||
const entry = checkupCurrentEntry;
|
||||
if (!entry) return;
|
||||
|
||||
setCheckupSession((prev) =>
|
||||
prev.map((x) => (x.itemId === entry.itemId ? { ...x, confirmed: true, result: 'correct' } : x))
|
||||
);
|
||||
goNextInCheckup();
|
||||
}
|
||||
|
||||
function openCurrentCheckupNo() {
|
||||
const entry = checkupCurrentEntry;
|
||||
if (!entry) return;
|
||||
setCheckupNoForm({
|
||||
status: entry.current.status || 'unpacked',
|
||||
placement: entry.current.placement || 'suitcase',
|
||||
lentTo: entry.current.lentTo || '',
|
||||
updateMasterList: false,
|
||||
});
|
||||
setCheckupFlowMode('edit');
|
||||
}
|
||||
|
||||
function saveCurrentCheckupNo() {
|
||||
const entry = checkupCurrentEntry;
|
||||
if (!entry) return;
|
||||
|
||||
const patch = {
|
||||
status: checkupNoForm.status,
|
||||
placement: checkupNoForm.placement,
|
||||
lentTo: checkupNoForm.status === 'lent-to' ? checkupNoForm.lentTo.trim() : '',
|
||||
};
|
||||
|
||||
setCheckupSession((prev) =>
|
||||
prev.map((x) =>
|
||||
x.itemId === entry.itemId
|
||||
? {
|
||||
...x,
|
||||
current: patch,
|
||||
confirmed: true,
|
||||
result: 'bad',
|
||||
}
|
||||
: x
|
||||
)
|
||||
);
|
||||
|
||||
if (checkupNoForm.updateMasterList && selectedTripId) {
|
||||
setData((prev) => {
|
||||
const items = prev.itemsByTrip[selectedTripId] || [];
|
||||
return {
|
||||
...prev,
|
||||
itemsByTrip: {
|
||||
...prev.itemsByTrip,
|
||||
[selectedTripId]: items.map((item) =>
|
||||
item.id === entry.itemId
|
||||
? {
|
||||
...item,
|
||||
status: patch.status,
|
||||
@@ -429,28 +527,27 @@ export default function AppRoot() {
|
||||
});
|
||||
}
|
||||
|
||||
setCheckupFixModalVisible(false);
|
||||
setCheckupFixTargetId(null);
|
||||
goNextInCheckup();
|
||||
}
|
||||
|
||||
function saveCheckup() {
|
||||
function saveCheckupSnapshot(sessionToSave) {
|
||||
if (!selectedTripId) {
|
||||
Alert.alert('No trip selected', 'Please select a trip first.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!checkupSession.length) {
|
||||
if (!sessionToSave.length) {
|
||||
Alert.alert('No items', 'Add items before creating a check-up.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const pending = checkupSession.filter((entry) => !entry.confirmed).length;
|
||||
const pending = sessionToSave.filter((entry) => !entry.confirmed).length;
|
||||
if (pending > 0) {
|
||||
Alert.alert('Incomplete', `Please confirm all items first (${pending} remaining).`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const snapshot = checkupSession.map((entry) => ({
|
||||
const snapshot = sessionToSave.map((entry) => ({
|
||||
itemId: entry.itemId,
|
||||
name: entry.name,
|
||||
category: entry.category,
|
||||
@@ -482,7 +579,15 @@ export default function AppRoot() {
|
||||
};
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function finishCheckupFlow() {
|
||||
const ok = saveCheckupSnapshot(checkupSession);
|
||||
if (!ok) return;
|
||||
|
||||
Alert.alert('Saved', 'Check-up snapshot saved.');
|
||||
closeCheckupFlow();
|
||||
createFreshCheckupSession();
|
||||
}
|
||||
|
||||
@@ -526,6 +631,7 @@ export default function AppRoot() {
|
||||
tripForm={tripForm}
|
||||
updateTripForm={updateTripForm}
|
||||
pickTripImage={() => pickImage((uri) => updateTripForm('imageUri', uri))}
|
||||
takeTripImage={() => takeImage((uri) => updateTripForm('imageUri', uri))}
|
||||
templateTrip={templateTrip}
|
||||
createTrip={createTrip}
|
||||
trips={data.trips}
|
||||
@@ -536,6 +642,8 @@ export default function AppRoot() {
|
||||
onInputFocus={onInputFocus}
|
||||
defaultTemplateTripId={data.defaultTemplateTripId}
|
||||
openDatePicker={openDatePicker}
|
||||
activeTripItemCount={selectedTripItems.length}
|
||||
activeTripCheckupCount={selectedTripCheckups.length}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -546,17 +654,16 @@ export default function AppRoot() {
|
||||
openAddItemModal={openAddItemModal}
|
||||
openEditItemModal={openEditItemModal}
|
||||
deleteItem={deleteItem}
|
||||
quickSetItemStatus={quickSetItemStatus}
|
||||
/>
|
||||
)}
|
||||
|
||||
{tab === 'checkup' && (
|
||||
<CheckupTab
|
||||
checkupSession={checkupSession}
|
||||
selectedTrip={selectedTrip}
|
||||
selectedTripItems={selectedTripItems}
|
||||
checkupStats={checkupStats}
|
||||
answerCheckupYes={answerCheckupYes}
|
||||
openFixModal={openFixModal}
|
||||
createFreshCheckupSession={createFreshCheckupSession}
|
||||
saveCheckup={saveCheckup}
|
||||
startCheckupFlow={startCheckupFlow}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -566,6 +673,7 @@ export default function AppRoot() {
|
||||
selectedTripCheckups={selectedTripCheckups}
|
||||
selectedCheckupId={selectedCheckupId}
|
||||
setSelectedCheckupId={setSelectedCheckupId}
|
||||
onDeleteCheckup={deleteCheckup}
|
||||
/>
|
||||
)}
|
||||
</ScrollView>
|
||||
@@ -587,15 +695,23 @@ export default function AppRoot() {
|
||||
setItemModalVisible={setItemModalVisible}
|
||||
updateItemForm={updateItemForm}
|
||||
pickItemImage={() => pickImage((uri) => updateItemForm('imageUri', uri))}
|
||||
takeItemImage={() => takeImage((uri) => updateItemForm('imageUri', uri))}
|
||||
saveItemFromModal={saveItemFromModal}
|
||||
/>
|
||||
|
||||
<CheckupFixModal
|
||||
visible={checkupFixModalVisible}
|
||||
checkupFixForm={checkupFixForm}
|
||||
setCheckupFixForm={setCheckupFixForm}
|
||||
setCheckupFixModalVisible={setCheckupFixModalVisible}
|
||||
saveFixModal={saveFixModal}
|
||||
<CheckupFlowModal
|
||||
visible={checkupFlowVisible}
|
||||
entry={checkupCurrentEntry}
|
||||
stepIndex={checkupFlowIndex}
|
||||
total={checkupSession.length}
|
||||
mode={checkupFlowMode}
|
||||
noForm={checkupNoForm}
|
||||
setNoForm={setCheckupNoForm}
|
||||
onClose={closeCheckupFlow}
|
||||
onYes={answerCurrentCheckupYes}
|
||||
onNo={openCurrentCheckupNo}
|
||||
onSaveNo={saveCurrentCheckupNo}
|
||||
onFinish={finishCheckupFlow}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
);
|
||||
|
||||
@@ -7,7 +7,10 @@ function statusAccent(status) {
|
||||
return STATUS_COLORS[status] || '#64748b';
|
||||
}
|
||||
|
||||
export default function ItemCard({ item, onEdit, onDelete }) {
|
||||
export default function ItemCard({ item, onEdit, onDelete, onQuickPack, onQuickUnpack }) {
|
||||
const isPacked = item.status === 'packed';
|
||||
const isUnpacked = item.status === 'unpacked';
|
||||
|
||||
return (
|
||||
<View style={styles.itemCard}>
|
||||
<View style={[styles.itemAccent, { backgroundColor: statusAccent(item.status) }]} />
|
||||
@@ -29,6 +32,16 @@ export default function ItemCard({ item, onEdit, onDelete }) {
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View style={styles.quickStatusRow}>
|
||||
<Pressable style={[styles.quickStatusBtn, isPacked && styles.quickStatusBtnActive]} onPress={onQuickPack}>
|
||||
<Text style={[styles.quickStatusBtnText, isPacked && styles.quickStatusBtnTextActive]}>Pack</Text>
|
||||
</Pressable>
|
||||
<Pressable style={[styles.quickStatusBtn, isUnpacked && styles.quickStatusBtnActive]} onPress={onQuickUnpack}>
|
||||
<Text style={[styles.quickStatusBtnText, isUnpacked && styles.quickStatusBtnTextActive]}>Unpack</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
{item.imageUri ? <Image source={{ uri: item.imageUri }} style={styles.previewImageSmall} /> : null}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -15,7 +15,7 @@ export default function CheckupFixModal({
|
||||
return (
|
||||
<Modal visible={visible} animationType="slide" transparent>
|
||||
<View style={styles.modalBackdrop}>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={styles.modalKeyboardWrap}>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={styles.modalKeyboardWrap}>
|
||||
<View style={styles.modalCard}>
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionTitle}>Update for this Check-Up</Text>
|
||||
@@ -24,7 +24,12 @@ export default function CheckupFixModal({
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
<ScrollView keyboardShouldPersistTaps="handled" showsVerticalScrollIndicator={false}>
|
||||
<ScrollView
|
||||
keyboardShouldPersistTaps="handled"
|
||||
keyboardDismissMode="interactive"
|
||||
contentContainerStyle={{ paddingBottom: 12 }}
|
||||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
<Field label="Status">
|
||||
<ChipGroup
|
||||
options={ITEM_STATUSES}
|
||||
|
||||
121
src/modals/CheckupFlowModal.js
Normal file
121
src/modals/CheckupFlowModal.js
Normal file
@@ -0,0 +1,121 @@
|
||||
import React from 'react';
|
||||
import { KeyboardAvoidingView, Modal, Platform, Pressable, ScrollView, Text, TextInput, View } from 'react-native';
|
||||
import { ITEM_PLACEMENTS, ITEM_STATUSES } from '../constants';
|
||||
import ChipGroup from '../components/ChipGroup';
|
||||
import Field from '../components/Field';
|
||||
import { styles } from '../styles';
|
||||
|
||||
export default function CheckupFlowModal({
|
||||
visible,
|
||||
entry,
|
||||
stepIndex,
|
||||
total,
|
||||
mode,
|
||||
noForm,
|
||||
setNoForm,
|
||||
onClose,
|
||||
onYes,
|
||||
onNo,
|
||||
onSaveNo,
|
||||
onFinish,
|
||||
}) {
|
||||
const finished = !entry;
|
||||
|
||||
return (
|
||||
<Modal visible={visible} animationType="slide" transparent>
|
||||
<View style={styles.modalBackdrop}>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={styles.modalKeyboardWrap}>
|
||||
<View style={styles.modalCard}>
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionTitle}>Check-Up</Text>
|
||||
<Pressable onPress={onClose}>
|
||||
<Text style={styles.closeText}>Close</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
{finished ? (
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.cardTitle}>Done. Save this snapshot?</Text>
|
||||
<Text style={styles.cardMeta}>All {total} items were checked.</Text>
|
||||
<Pressable style={styles.primaryBtn} onPress={onFinish}>
|
||||
<Text style={styles.primaryBtnText}>Save Check-Up Snapshot</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
) : (
|
||||
<ScrollView
|
||||
keyboardShouldPersistTaps="handled"
|
||||
keyboardDismissMode="interactive"
|
||||
contentContainerStyle={{ paddingBottom: 12 }}
|
||||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
<Text style={styles.tripHistoryLabel}>
|
||||
Item {stepIndex + 1} / {total}
|
||||
</Text>
|
||||
<Text style={styles.cardTitle}>{entry.name}</Text>
|
||||
<Text style={styles.cardMeta}>{entry.category || 'uncategorized'}</Text>
|
||||
<Text style={styles.cardMeta}>
|
||||
Current: {entry.current.status} · {entry.current.placement}
|
||||
{entry.current.status === 'lent-to' && entry.current.lentTo ? ` · ${entry.current.lentTo}` : ''}
|
||||
</Text>
|
||||
|
||||
{mode === 'question' ? (
|
||||
<View style={styles.answerRowWide}>
|
||||
<Pressable style={styles.answerYesWide} onPress={onYes}>
|
||||
<Text style={styles.answerText}>Yes, correct</Text>
|
||||
</Pressable>
|
||||
<Pressable style={styles.answerNoWide} onPress={onNo}>
|
||||
<Text style={styles.answerText}>No, update</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
) : (
|
||||
<View style={styles.section}>
|
||||
<Field label="Status">
|
||||
<ChipGroup
|
||||
options={ITEM_STATUSES}
|
||||
value={noForm.status}
|
||||
onChange={(v) => setNoForm((prev) => ({ ...prev, status: v }))}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="Placement">
|
||||
<ChipGroup
|
||||
options={ITEM_PLACEMENTS}
|
||||
value={noForm.placement}
|
||||
onChange={(v) => setNoForm((prev) => ({ ...prev, placement: v }))}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
{noForm.status === 'lent-to' ? (
|
||||
<Field label="Lent to">
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={noForm.lentTo}
|
||||
onChangeText={(v) => setNoForm((prev) => ({ ...prev, lentTo: v }))}
|
||||
placeholder="Person name"
|
||||
placeholderTextColor="#6b7280"
|
||||
/>
|
||||
</Field>
|
||||
) : null}
|
||||
|
||||
<Pressable
|
||||
style={styles.inlineToggle}
|
||||
onPress={() => setNoForm((prev) => ({ ...prev, updateMasterList: !prev.updateMasterList }))}
|
||||
>
|
||||
<Text style={styles.inlineToggleText}>
|
||||
{noForm.updateMasterList ? '☑' : '☐'} Also update item in trip list
|
||||
</Text>
|
||||
</Pressable>
|
||||
|
||||
<Pressable style={styles.primaryBtn} onPress={onSaveNo}>
|
||||
<Text style={styles.primaryBtnText}>Save update + next</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
)}
|
||||
</ScrollView>
|
||||
)}
|
||||
</View>
|
||||
</KeyboardAvoidingView>
|
||||
</View>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -11,12 +11,13 @@ export default function ItemModal({
|
||||
setItemModalVisible,
|
||||
updateItemForm,
|
||||
pickItemImage,
|
||||
takeItemImage,
|
||||
saveItemFromModal,
|
||||
}) {
|
||||
return (
|
||||
<Modal visible={visible} animationType="slide" transparent>
|
||||
<View style={styles.modalBackdrop}>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={styles.modalKeyboardWrap}>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={styles.modalKeyboardWrap}>
|
||||
<View style={styles.modalCard}>
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionTitle}>{itemForm.id ? 'Update Item' : 'Add Item'}</Text>
|
||||
@@ -25,7 +26,12 @@ export default function ItemModal({
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
<ScrollView keyboardShouldPersistTaps="handled" showsVerticalScrollIndicator={false}>
|
||||
<ScrollView
|
||||
keyboardShouldPersistTaps="handled"
|
||||
keyboardDismissMode="interactive"
|
||||
contentContainerStyle={{ paddingBottom: 12 }}
|
||||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
<Field label="Name">
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
@@ -76,9 +82,14 @@ export default function ItemModal({
|
||||
</Field>
|
||||
) : null}
|
||||
|
||||
<Pressable style={styles.secondaryBtn} onPress={pickItemImage}>
|
||||
<Text style={styles.secondaryBtnText}>{itemForm.imageUri ? 'Change image' : 'Add image'}</Text>
|
||||
<View style={styles.actionRow}>
|
||||
<Pressable style={[styles.secondaryBtnTight, styles.flex]} onPress={takeItemImage}>
|
||||
<Text style={styles.secondaryBtnText}>Take photo</Text>
|
||||
</Pressable>
|
||||
<Pressable style={[styles.secondaryBtnTight, styles.flex]} onPress={pickItemImage}>
|
||||
<Text style={styles.secondaryBtnText}>{itemForm.imageUri ? 'From gallery (change)' : 'From gallery'}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
{!!itemForm.imageUri && <Image source={{ uri: itemForm.imageUri }} style={styles.previewImageSmall} />}
|
||||
|
||||
<Pressable style={styles.primaryBtn} onPress={saveItemFromModal}>
|
||||
|
||||
@@ -117,6 +117,32 @@ export const styles = StyleSheet.create({
|
||||
marginTop: -2,
|
||||
marginBottom: 2,
|
||||
},
|
||||
tripHeroCard: {
|
||||
backgroundColor: '#0f172a',
|
||||
borderRadius: 18,
|
||||
borderWidth: 1,
|
||||
borderColor: '#334155',
|
||||
padding: 12,
|
||||
gap: 8,
|
||||
},
|
||||
tripHeroImage: {
|
||||
width: '100%',
|
||||
height: 180,
|
||||
borderRadius: 12,
|
||||
backgroundColor: '#111827',
|
||||
},
|
||||
tripHeroTitle: {
|
||||
color: '#f8fafc',
|
||||
fontWeight: '800',
|
||||
fontSize: 22,
|
||||
},
|
||||
tripListTitle: {
|
||||
color: '#cbd5e1',
|
||||
fontWeight: '700',
|
||||
fontSize: 13,
|
||||
letterSpacing: 0.4,
|
||||
textTransform: 'uppercase',
|
||||
},
|
||||
|
||||
fieldWrap: {
|
||||
gap: 6,
|
||||
@@ -211,6 +237,11 @@ export const styles = StyleSheet.create({
|
||||
color: '#dbeafe',
|
||||
fontWeight: '700',
|
||||
},
|
||||
actionRow: {
|
||||
flexDirection: 'row',
|
||||
gap: 8,
|
||||
marginTop: 4,
|
||||
},
|
||||
|
||||
inlineToggle: {
|
||||
marginTop: 2,
|
||||
@@ -266,6 +297,31 @@ export const styles = StyleSheet.create({
|
||||
marginTop: 2,
|
||||
fontSize: 13,
|
||||
},
|
||||
quickStatusRow: {
|
||||
flexDirection: 'row',
|
||||
gap: 8,
|
||||
marginTop: 2,
|
||||
},
|
||||
quickStatusBtn: {
|
||||
paddingVertical: 6,
|
||||
paddingHorizontal: 12,
|
||||
borderRadius: 999,
|
||||
borderWidth: 1,
|
||||
borderColor: '#334155',
|
||||
backgroundColor: '#0b1220',
|
||||
},
|
||||
quickStatusBtnActive: {
|
||||
borderColor: '#60a5fa',
|
||||
backgroundColor: '#1d2a3a',
|
||||
},
|
||||
quickStatusBtnText: {
|
||||
color: '#cbd5e1',
|
||||
fontWeight: '700',
|
||||
fontSize: 12,
|
||||
},
|
||||
quickStatusBtnTextActive: {
|
||||
color: '#dbeafe',
|
||||
},
|
||||
|
||||
answerRow: {
|
||||
marginTop: 8,
|
||||
@@ -293,6 +349,28 @@ export const styles = StyleSheet.create({
|
||||
color: '#f8fafc',
|
||||
fontWeight: '700',
|
||||
},
|
||||
answerRowWide: {
|
||||
marginTop: 14,
|
||||
gap: 10,
|
||||
},
|
||||
answerYesWide: {
|
||||
backgroundColor: '#163223',
|
||||
borderWidth: 1,
|
||||
borderColor: '#1f7a4e',
|
||||
borderRadius: 10,
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 11,
|
||||
alignItems: 'center',
|
||||
},
|
||||
answerNoWide: {
|
||||
backgroundColor: '#3b1d22',
|
||||
borderWidth: 1,
|
||||
borderColor: '#7f1d1d',
|
||||
borderRadius: 10,
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 11,
|
||||
alignItems: 'center',
|
||||
},
|
||||
answerStateDot: {
|
||||
width: 10,
|
||||
height: 10,
|
||||
@@ -400,20 +478,23 @@ export const styles = StyleSheet.create({
|
||||
modalBackdrop: {
|
||||
flex: 1,
|
||||
backgroundColor: 'rgba(2,6,23,0.72)',
|
||||
justifyContent: 'flex-end',
|
||||
paddingHorizontal: 12,
|
||||
},
|
||||
modalKeyboardWrap: {
|
||||
flex: 1,
|
||||
width: '100%',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
modalCard: {
|
||||
maxHeight: '87%',
|
||||
width: '96%',
|
||||
maxHeight: '90%',
|
||||
backgroundColor: '#0f172a',
|
||||
borderTopLeftRadius: 18,
|
||||
borderTopRightRadius: 18,
|
||||
borderRadius: 20,
|
||||
borderWidth: 1,
|
||||
borderColor: '#1e293b',
|
||||
padding: 14,
|
||||
gap: 8,
|
||||
padding: 16,
|
||||
gap: 10,
|
||||
},
|
||||
closeText: {
|
||||
color: '#93c5fd',
|
||||
|
||||
@@ -2,24 +2,19 @@ import React from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
import { styles } from '../styles';
|
||||
|
||||
export default function CheckupTab({
|
||||
checkupSession,
|
||||
checkupStats,
|
||||
answerCheckupYes,
|
||||
openFixModal,
|
||||
createFreshCheckupSession,
|
||||
saveCheckup,
|
||||
}) {
|
||||
export default function CheckupTab({ selectedTrip, selectedTripItems, checkupStats, startCheckupFlow }) {
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionTitle}>Check-Up</Text>
|
||||
<Pressable style={styles.secondaryBtnTight} onPress={createFreshCheckupSession}>
|
||||
<Text style={styles.secondaryBtnText}>Restart</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
{!!checkupSession.length && (
|
||||
{!selectedTrip ? <Text style={styles.muted}>Select a trip first.</Text> : null}
|
||||
{selectedTrip && selectedTripItems.length === 0 ? <Text style={styles.muted}>No items for this trip yet.</Text> : null}
|
||||
|
||||
{selectedTrip && selectedTripItems.length > 0 ? (
|
||||
<View style={styles.cardSoft}>
|
||||
<Text style={styles.cardTitle}>Run a check-up for {selectedTrip.name}</Text>
|
||||
<Text style={styles.cardMeta}>{selectedTripItems.length} items will be checked one by one.</Text>
|
||||
|
||||
<View style={styles.statsRow}>
|
||||
<View style={[styles.statPill, styles.statPillCorrect]}>
|
||||
<Text style={styles.statPillText}>Correct: {checkupStats.correct}</Text>
|
||||
@@ -31,42 +26,12 @@ export default function CheckupTab({
|
||||
<Text style={styles.statPillText}>Pending: {checkupStats.pending}</Text>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{checkupSession.length === 0 ? <Text style={styles.muted}>No items for this trip yet.</Text> : null}
|
||||
|
||||
{checkupSession.map((entry) => (
|
||||
<View key={entry.itemId} style={styles.cardSoft}>
|
||||
<Text style={styles.cardTitle}>{entry.name}</Text>
|
||||
<Text style={styles.cardMeta}>{entry.category || 'uncategorized'}</Text>
|
||||
<Text style={styles.cardMeta}>
|
||||
{entry.current.status} · {entry.current.placement}
|
||||
{entry.current.status === 'lent-to' && entry.current.lentTo ? ` · ${entry.current.lentTo}` : ''}
|
||||
</Text>
|
||||
|
||||
<View style={styles.answerRow}>
|
||||
<Pressable style={styles.answerYes} onPress={() => answerCheckupYes(entry.itemId)}>
|
||||
<Text style={styles.answerText}>Yes</Text>
|
||||
<Pressable style={styles.primaryBtn} onPress={startCheckupFlow}>
|
||||
<Text style={styles.primaryBtnText}>Start Check-Up</Text>
|
||||
</Pressable>
|
||||
<Pressable style={styles.answerNo} onPress={() => openFixModal(entry.itemId)}>
|
||||
<Text style={styles.answerText}>No</Text>
|
||||
</Pressable>
|
||||
<View
|
||||
style={[
|
||||
styles.answerStateDot,
|
||||
entry.result === 'correct' ? styles.answerStateDotOn : null,
|
||||
entry.result === 'bad' ? styles.answerStateDotBad : null,
|
||||
]}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
|
||||
{!!checkupSession.length && (
|
||||
<Pressable style={styles.primaryBtn} onPress={saveCheckup}>
|
||||
<Text style={styles.primaryBtnText}>Save Check-Up Snapshot</Text>
|
||||
</Pressable>
|
||||
)}
|
||||
) : null}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
import React from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
import { Alert, Pressable, Text, View } from 'react-native';
|
||||
import { styles } from '../styles';
|
||||
|
||||
export default function HistoryTab({ selectedTrip, selectedTripCheckups, selectedCheckupId, setSelectedCheckupId }) {
|
||||
export default function HistoryTab({
|
||||
selectedTrip,
|
||||
selectedTripCheckups,
|
||||
selectedCheckupId,
|
||||
setSelectedCheckupId,
|
||||
onDeleteCheckup,
|
||||
}) {
|
||||
function askDelete(checkup) {
|
||||
Alert.alert('Delete check-up?', 'This snapshot will be removed from history.', [
|
||||
{ text: 'Cancel', style: 'cancel' },
|
||||
{
|
||||
text: 'Delete',
|
||||
style: 'destructive',
|
||||
onPress: () => onDeleteCheckup(checkup.id),
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>History</Text>
|
||||
@@ -13,13 +30,17 @@ export default function HistoryTab({ selectedTrip, selectedTripCheckups, selecte
|
||||
|
||||
{selectedTripCheckups.map((checkup) => (
|
||||
<View key={checkup.id} style={styles.cardSoft}>
|
||||
<Pressable onPress={() => setSelectedCheckupId((prev) => (prev === checkup.id ? null : checkup.id))}>
|
||||
<Pressable
|
||||
onPress={() => setSelectedCheckupId((prev) => (prev === checkup.id ? null : checkup.id))}
|
||||
onLongPress={() => askDelete(checkup)}
|
||||
delayLongPress={280}
|
||||
>
|
||||
<Text style={styles.cardTitle}>{new Date(checkup.createdAt).toLocaleString()}</Text>
|
||||
<Text style={styles.cardMeta}>
|
||||
{checkup.snapshot.length} items · correct: {checkup.stats?.correct ?? checkup.snapshot.filter((x) => x.result === 'correct').length} · bad:{' '}
|
||||
{checkup.stats?.bad ?? checkup.snapshot.filter((x) => x.result === 'bad').length}
|
||||
</Text>
|
||||
<Text style={styles.cardMeta}>{selectedCheckupId === checkup.id ? 'Tap to collapse' : 'Tap to open'}</Text>
|
||||
<Text style={styles.cardMeta}>{selectedCheckupId === checkup.id ? 'Tap to collapse' : 'Tap to open'} · long hold to delete</Text>
|
||||
</Pressable>
|
||||
|
||||
{selectedCheckupId === checkup.id ? (
|
||||
|
||||
@@ -3,7 +3,14 @@ import { Pressable, Text, View } from 'react-native';
|
||||
import ItemCard from '../components/ItemCard';
|
||||
import { styles } from '../styles';
|
||||
|
||||
export default function ItemsTab({ selectedTrip, selectedTripItems, openAddItemModal, openEditItemModal, deleteItem }) {
|
||||
export default function ItemsTab({
|
||||
selectedTrip,
|
||||
selectedTripItems,
|
||||
openAddItemModal,
|
||||
openEditItemModal,
|
||||
deleteItem,
|
||||
quickSetItemStatus,
|
||||
}) {
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<View style={styles.sectionRow}>
|
||||
@@ -17,7 +24,14 @@ export default function ItemsTab({ selectedTrip, selectedTripItems, openAddItemM
|
||||
{selectedTripItems.length === 0 && selectedTrip ? <Text style={styles.muted}>No items yet.</Text> : null}
|
||||
|
||||
{selectedTripItems.map((item) => (
|
||||
<ItemCard key={item.id} item={item} onEdit={openEditItemModal} onDelete={deleteItem} />
|
||||
<ItemCard
|
||||
key={item.id}
|
||||
item={item}
|
||||
onEdit={openEditItemModal}
|
||||
onDelete={deleteItem}
|
||||
onQuickPack={() => quickSetItemStatus(item.id, 'packed')}
|
||||
onQuickUnpack={() => quickSetItemStatus(item.id, 'unpacked')}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { Image, Pressable, Text, TextInput, View } from 'react-native';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { Image, KeyboardAvoidingView, Modal, Platform, Pressable, ScrollView, Text, TextInput, View } from 'react-native';
|
||||
import Field from '../components/Field';
|
||||
import { styles } from '../styles';
|
||||
|
||||
@@ -17,6 +17,7 @@ export default function TripsTab({
|
||||
tripForm,
|
||||
updateTripForm,
|
||||
pickTripImage,
|
||||
takeTripImage,
|
||||
templateTrip,
|
||||
createTrip,
|
||||
trips,
|
||||
@@ -27,12 +28,95 @@ export default function TripsTab({
|
||||
onInputFocus,
|
||||
defaultTemplateTripId,
|
||||
openDatePicker,
|
||||
activeTripItemCount,
|
||||
activeTripCheckupCount,
|
||||
}) {
|
||||
const [createModalVisible, setCreateModalVisible] = useState(false);
|
||||
const [viewTripId, setViewTripId] = useState(null);
|
||||
|
||||
const activeTrip = useMemo(() => trips.find((trip) => trip.id === selectedTripId) || null, [trips, selectedTripId]);
|
||||
const viewingTrip = useMemo(() => trips.find((trip) => trip.id === viewTripId) || null, [trips, viewTripId]);
|
||||
|
||||
function submitCreateTrip() {
|
||||
const ok = createTrip();
|
||||
if (ok) setCreateModalVisible(false);
|
||||
}
|
||||
|
||||
function applyTemplateFromView() {
|
||||
if (!viewingTrip) return;
|
||||
setTripAsTemplate(viewingTrip.id);
|
||||
}
|
||||
|
||||
function deleteFromView() {
|
||||
if (!viewingTrip) return;
|
||||
const tripId = viewingTrip.id;
|
||||
setViewTripId(null);
|
||||
deleteTrip(tripId);
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionTitle}>Trips</Text>
|
||||
<Pressable style={styles.primaryBtnTight} onPress={() => setCreateModalVisible(true)}>
|
||||
<Text style={styles.primaryBtnText}>+ New Trip</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
<View style={styles.cardSoft}>
|
||||
{activeTrip ? (
|
||||
<View style={styles.tripHeroCard}>
|
||||
{activeTrip.imageUri ? <Image source={{ uri: activeTrip.imageUri }} style={styles.tripHeroImage} /> : null}
|
||||
<Text style={styles.tripHeroTitle}>{activeTrip.name}</Text>
|
||||
<Text style={styles.cardMeta}>{activeTrip.location || 'No location'} · {activeTrip.startDate} → {activeTrip.endDate}</Text>
|
||||
<Text style={styles.cardMeta}>{activeTripItemCount} items · {activeTripCheckupCount} check-ups</Text>
|
||||
</View>
|
||||
) : (
|
||||
<Text style={styles.muted}>Create your first trip to get started.</Text>
|
||||
)}
|
||||
|
||||
<Text style={styles.tripListTitle}>All Trips</Text>
|
||||
|
||||
{trips
|
||||
.slice()
|
||||
.sort((a, b) => b.startDate.localeCompare(a.startDate))
|
||||
.map((trip) => (
|
||||
<View key={trip.id} style={[styles.card, selectedTripId === trip.id && styles.cardActive]}>
|
||||
<View style={styles.cardRow}>
|
||||
<View style={styles.flex}>
|
||||
<Text style={styles.cardTitle}>{trip.name}</Text>
|
||||
<Text style={styles.cardMeta}>{trip.location || 'No location'} · {trip.startDate} → {trip.endDate}</Text>
|
||||
<Text style={styles.cardMeta}>{defaultTemplateTripId === trip.id ? 'Default template' : ' '}</Text>
|
||||
</View>
|
||||
<View style={styles.stackButtons}>
|
||||
<Pressable style={styles.miniBtn} onPress={() => chooseTrip(trip.id)}>
|
||||
<Text style={styles.miniBtnText}>Select</Text>
|
||||
</Pressable>
|
||||
<Pressable style={styles.miniBtn} onPress={() => setViewTripId(trip.id)}>
|
||||
<Text style={styles.miniBtnText}>View</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
{trip.imageUri ? <Image source={{ uri: trip.imageUri }} style={styles.previewImageSmall} /> : null}
|
||||
</View>
|
||||
))}
|
||||
|
||||
<Modal visible={createModalVisible} animationType="slide" transparent>
|
||||
<View style={styles.modalBackdrop}>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={styles.modalKeyboardWrap}>
|
||||
<View style={styles.modalCard}>
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionTitle}>Create Trip</Text>
|
||||
<Pressable onPress={() => setCreateModalVisible(false)}>
|
||||
<Text style={styles.closeText}>Close</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
<ScrollView
|
||||
keyboardShouldPersistTaps="handled"
|
||||
keyboardDismissMode="interactive"
|
||||
contentContainerStyle={{ paddingBottom: 12 }}
|
||||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
<Field label="Name">
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
@@ -58,9 +142,14 @@ export default function TripsTab({
|
||||
<DateField label="Start Date" value={tripForm.startDate} onPress={() => openDatePicker('startDate')} />
|
||||
<DateField label="End Date" value={tripForm.endDate} onPress={() => openDatePicker('endDate')} />
|
||||
|
||||
<Pressable style={styles.secondaryBtn} onPress={pickTripImage}>
|
||||
<Text style={styles.secondaryBtnText}>{tripForm.imageUri ? 'Change trip image' : 'Add trip image'}</Text>
|
||||
<View style={styles.actionRow}>
|
||||
<Pressable style={[styles.secondaryBtnTight, styles.flex]} onPress={takeTripImage}>
|
||||
<Text style={styles.secondaryBtnText}>Take photo</Text>
|
||||
</Pressable>
|
||||
<Pressable style={[styles.secondaryBtnTight, styles.flex]} onPress={pickTripImage}>
|
||||
<Text style={styles.secondaryBtnText}>{tripForm.imageUri ? 'From gallery (change)' : 'From gallery'}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
{tripForm.imageUri ? <Image source={{ uri: tripForm.imageUri }} style={styles.previewImage} /> : null}
|
||||
|
||||
@@ -76,37 +165,52 @@ export default function TripsTab({
|
||||
<Text style={styles.inlineToggleText}>{tripForm.setAsDefaultTemplate ? '☑' : '☐'} Set as default template</Text>
|
||||
</Pressable>
|
||||
|
||||
<Pressable style={styles.primaryBtn} onPress={createTrip}>
|
||||
<Pressable style={styles.primaryBtn} onPress={submitCreateTrip}>
|
||||
<Text style={styles.primaryBtnText}>Create Trip</Text>
|
||||
</Pressable>
|
||||
</ScrollView>
|
||||
</View>
|
||||
</KeyboardAvoidingView>
|
||||
</View>
|
||||
</Modal>
|
||||
|
||||
<Modal visible={!!viewingTrip} animationType="slide" transparent>
|
||||
<View style={styles.modalBackdrop}>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={styles.modalKeyboardWrap}>
|
||||
<View style={styles.modalCard}>
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionTitle}>Trip View</Text>
|
||||
<Pressable onPress={() => setViewTripId(null)}>
|
||||
<Text style={styles.closeText}>Close</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
{trips
|
||||
.slice()
|
||||
.sort((a, b) => b.startDate.localeCompare(a.startDate))
|
||||
.map((trip) => (
|
||||
<View key={trip.id} style={[styles.card, selectedTripId === trip.id && styles.cardActive]}>
|
||||
<View style={styles.cardRow}>
|
||||
<View style={styles.flex}>
|
||||
<Text style={styles.cardTitle}>{trip.name}</Text>
|
||||
<Text style={styles.cardMeta}>{trip.location || 'No location'} · {trip.startDate} → {trip.endDate}</Text>
|
||||
<Text style={styles.cardMeta}>{defaultTemplateTripId === trip.id ? 'Default template' : ' '}</Text>
|
||||
</View>
|
||||
<View style={styles.stackButtons}>
|
||||
<Pressable style={styles.miniBtn} onPress={() => chooseTrip(trip.id)}>
|
||||
<Text style={styles.miniBtnText}>Select</Text>
|
||||
{viewingTrip ? (
|
||||
<ScrollView
|
||||
keyboardShouldPersistTaps="handled"
|
||||
keyboardDismissMode="interactive"
|
||||
contentContainerStyle={{ paddingBottom: 12 }}
|
||||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
{viewingTrip.imageUri ? <Image source={{ uri: viewingTrip.imageUri }} style={styles.previewImage} /> : null}
|
||||
<Text style={styles.tripHeroTitle}>{viewingTrip.name}</Text>
|
||||
<Text style={styles.cardMeta}>{viewingTrip.location || 'No location'}</Text>
|
||||
<Text style={styles.cardMeta}>{viewingTrip.startDate} → {viewingTrip.endDate}</Text>
|
||||
<Text style={styles.cardMeta}>{defaultTemplateTripId === viewingTrip.id ? 'Default template trip' : 'Not default template'}</Text>
|
||||
|
||||
<Pressable style={styles.secondaryBtn} onPress={applyTemplateFromView}>
|
||||
<Text style={styles.secondaryBtnText}>Set as Template</Text>
|
||||
</Pressable>
|
||||
<Pressable style={styles.miniBtn} onPress={() => setTripAsTemplate(trip.id)}>
|
||||
<Text style={styles.miniBtnText}>Template</Text>
|
||||
</Pressable>
|
||||
<Pressable style={styles.miniBtnDanger} onPress={() => deleteTrip(trip.id)}>
|
||||
<Text style={styles.miniBtnText}>Delete</Text>
|
||||
|
||||
<Pressable style={styles.miniBtnDanger} onPress={deleteFromView}>
|
||||
<Text style={styles.miniBtnText}>Delete Trip</Text>
|
||||
</Pressable>
|
||||
</ScrollView>
|
||||
) : null}
|
||||
</View>
|
||||
</KeyboardAvoidingView>
|
||||
</View>
|
||||
{trip.imageUri ? <Image source={{ uri: trip.imageUri }} style={styles.previewImageSmall} /> : null}
|
||||
</View>
|
||||
))}
|
||||
</Modal>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,3 +23,34 @@ export function findActiveTripId(trips) {
|
||||
});
|
||||
return active?.id || null;
|
||||
}
|
||||
|
||||
export function findNextTripId(trips) {
|
||||
const today = parseYMD(todayYMD());
|
||||
if (!today) return null;
|
||||
|
||||
const next = trips
|
||||
.map((trip) => ({ id: trip.id, start: parseYMD(trip.startDate) }))
|
||||
.filter((trip) => !!trip.start && trip.start >= today)
|
||||
.sort((a, b) => a.start - b.start)[0];
|
||||
|
||||
return next?.id || null;
|
||||
}
|
||||
|
||||
export function findBestTripId(trips) {
|
||||
const activeTripId = findActiveTripId(trips);
|
||||
if (activeTripId) return activeTripId;
|
||||
|
||||
const nextTripId = findNextTripId(trips);
|
||||
if (nextTripId) return nextTripId;
|
||||
|
||||
const latestPast = trips
|
||||
.map((trip) => ({ id: trip.id, end: parseYMD(trip.endDate), start: parseYMD(trip.startDate) }))
|
||||
.filter((trip) => !!trip.end || !!trip.start)
|
||||
.sort((a, b) => {
|
||||
const aTime = (a.end || a.start).getTime();
|
||||
const bTime = (b.end || b.start).getTime();
|
||||
return bTime - aTime;
|
||||
})[0];
|
||||
|
||||
return latestPast?.id || null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user