few cosmetic fixes
This commit is contained in:
@@ -90,6 +90,7 @@ export default function FormScreen() {
|
|||||||
const result = await launchCameraAsync({
|
const result = await launchCameraAsync({
|
||||||
allowsEditing: false,
|
allowsEditing: false,
|
||||||
base64: true,
|
base64: true,
|
||||||
|
quality: 0.2,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result.canceled && result.assets && result.assets.length > 0) {
|
if (!result.canceled && result.assets && result.assets.length > 0) {
|
||||||
|
|||||||
@@ -3,28 +3,37 @@ import {
|
|||||||
StyleSheet,
|
StyleSheet,
|
||||||
FlatList,
|
FlatList,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import { useTheme, Card, Text, Button } from "react-native-paper";
|
import {useTheme, Card, Text, Button, ActivityIndicator} from "react-native-paper";
|
||||||
import { Link } from "expo-router";
|
import {Link} from "expo-router";
|
||||||
import useLocationStore from "@/locationStore";
|
import useLocationStore from "@/locationStore";
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { locations } = useLocationStore();
|
const {locations} = useLocationStore();
|
||||||
|
const loading = useLocationStore((state) => state.loading);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<View style={[styles.container, {backgroundColor: theme.colors.background}]}>
|
||||||
|
<ActivityIndicator size="large" color={theme.colors.primary}/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
style={[styles.container, { backgroundColor: theme.colors.background }]}
|
style={[styles.container, {backgroundColor: theme.colors.background}]}
|
||||||
>
|
>
|
||||||
<FlatList
|
<FlatList
|
||||||
data={locations}
|
data={locations}
|
||||||
keyExtractor={(item) => item.id.toString()}
|
keyExtractor={(item) => item.id.toString()}
|
||||||
renderItem={({ item }) => (
|
renderItem={({item}) => (
|
||||||
<Card style={{ margin: 10 }}>
|
<Card style={{margin: 10}}>
|
||||||
<Card.Cover
|
<Card.Cover
|
||||||
style={{ marginBottom: 10 }}
|
style={{marginBottom: 10}}
|
||||||
source={item.imageSource}
|
source={item.imageSource}
|
||||||
/>
|
/>
|
||||||
<Card.Content style={{ marginBottom: 10 }}>
|
<Card.Content style={{marginBottom: 10}}>
|
||||||
<Text variant="titleLarge">{item.name}</Text>
|
<Text variant="titleLarge">{item.name}</Text>
|
||||||
<Text variant="bodyMedium">
|
<Text variant="bodyMedium">
|
||||||
{item.description && item.description.split(".")[0]}...
|
{item.description && item.description.split(".")[0]}...
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ export default function RootLayout() {
|
|||||||
fetchLocations();
|
fetchLocations();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
console.log();
|
|
||||||
const deleteLocation = useLocationStore((state) => state.deleteLocation);
|
const deleteLocation = useLocationStore((state) => state.deleteLocation);
|
||||||
|
|
||||||
const handleDelete = async (id) => {
|
const handleDelete = async (id) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { View, ScrollView, StyleSheet } from "react-native";
|
import { View, ScrollView, StyleSheet } from "react-native";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useTheme, Text, Card } from "react-native-paper";
|
import {useTheme, Text, Card, ActivityIndicator} from "react-native-paper";
|
||||||
import { useLocalSearchParams } from "expo-router";
|
import { useLocalSearchParams } from "expo-router";
|
||||||
import useLocationStore from "@/locationStore";
|
import useLocationStore from "@/locationStore";
|
||||||
|
|
||||||
@@ -19,7 +19,15 @@ export default function Location() {
|
|||||||
}
|
}
|
||||||
}, [location, loading, fetchLocations]);
|
}, [location, loading, fetchLocations]);
|
||||||
|
|
||||||
if (loading || !location) {
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<View style={[styles.container, {backgroundColor: theme.colors.background}]}>
|
||||||
|
<ActivityIndicator size="large" color={theme.colors.primary}/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!location) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.text}>Brak lokalizacji - {id}</Text>
|
<Text style={styles.text}>Brak lokalizacji - {id}</Text>
|
||||||
@@ -27,6 +35,7 @@ export default function Location() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[styles.container, {backgroundColor: theme.colors.background}]}>
|
<View style={[styles.container, {backgroundColor: theme.colors.background}]}>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ import {
|
|||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
View,
|
View,
|
||||||
ActivityIndicator,
|
ActivityIndicator,
|
||||||
|
Image,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import {TextInput, Button, Snackbar, useTheme} from "react-native-paper";
|
import {TextInput, Button, Snackbar, useTheme, Text} from "react-native-paper";
|
||||||
import {useLocalSearchParams, useRouter} from "expo-router";
|
import {useLocalSearchParams, useRouter} from "expo-router";
|
||||||
import useLocationStore from "@/locationStore";
|
import useLocationStore from "@/locationStore";
|
||||||
|
import {normalizeImageSource} from "@/api/locations";
|
||||||
|
|
||||||
export default function EditLocation() {
|
export default function EditLocation() {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -89,6 +91,16 @@ export default function EditLocation() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isBase64Image = (str) => {
|
||||||
|
let image = normalizeImageSource(str);
|
||||||
|
return image && (
|
||||||
|
image.uri.startsWith('data:image/jpeg;base64,') ||
|
||||||
|
image.uri.startsWith('data:image/png;base64,') ||
|
||||||
|
image.uri.startsWith('data:image/gif;base64,') ||
|
||||||
|
image.uri.startsWith('data:image/webp;base64,')
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
@@ -99,6 +111,14 @@ export default function EditLocation() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!formData) {
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<Text style={styles.text}>Brak lokalizacji - {id}</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
style={{flex: 1}}
|
style={{flex: 1}}
|
||||||
@@ -112,6 +132,30 @@ export default function EditLocation() {
|
|||||||
>
|
>
|
||||||
{message}
|
{message}
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
|
|
||||||
|
{isBase64Image(formData.image) ? (
|
||||||
|
<View style={styles.imageContainer}>
|
||||||
|
<Text style={{color: theme.colors.onBackground, marginBottom: 5}}>
|
||||||
|
Aktualne zdjęcie:
|
||||||
|
</Text>
|
||||||
|
<Image
|
||||||
|
source={normalizeImageSource(formData.image)}
|
||||||
|
style={styles.imagePreview}
|
||||||
|
resizeMode="contain"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<TextInput
|
||||||
|
mode="outlined"
|
||||||
|
label="Link do zdjęcia"
|
||||||
|
multiline={true}
|
||||||
|
placeholder="Wpisz link do zdjęcia"
|
||||||
|
style={{margin: 10, width: "100%"}}
|
||||||
|
value={formData.image}
|
||||||
|
onChangeText={(e) => setFormData({...formData, image: e})}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
label="Nazwa"
|
label="Nazwa"
|
||||||
@@ -129,15 +173,6 @@ export default function EditLocation() {
|
|||||||
value={formData.description}
|
value={formData.description}
|
||||||
onChangeText={(e) => setFormData({...formData, description: e})}
|
onChangeText={(e) => setFormData({...formData, description: e})}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
|
||||||
mode="outlined"
|
|
||||||
label="Link do zdjęcia"
|
|
||||||
multiline={true}
|
|
||||||
placeholder="Wpisz link do zdjęcia"
|
|
||||||
style={{margin: 10, width: "100%"}}
|
|
||||||
value={formData.image}
|
|
||||||
onChangeText={(e) => setFormData({...formData, image: e})}
|
|
||||||
/>
|
|
||||||
<TextInput
|
<TextInput
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
label="Powierzchnia"
|
label="Powierzchnia"
|
||||||
@@ -194,4 +229,15 @@ const styles = StyleSheet.create({
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
},
|
},
|
||||||
|
imageContainer: {
|
||||||
|
margin: 10,
|
||||||
|
width: "100%",
|
||||||
|
alignItems: "center",
|
||||||
|
padding: 10,
|
||||||
|
},
|
||||||
|
imagePreview: {
|
||||||
|
width: "100%",
|
||||||
|
height: 200,
|
||||||
|
borderRadius: 5,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { create } from "zustand";
|
import {create} from "zustand";
|
||||||
import * as api from "@/api/locations";
|
import * as api from "@/api/locations";
|
||||||
|
|
||||||
const useLocationStore = create((set, get) => ({
|
const useLocationStore = create((set, get) => ({
|
||||||
@@ -7,17 +7,17 @@ const useLocationStore = create((set, get) => ({
|
|||||||
error: null,
|
error: null,
|
||||||
|
|
||||||
fetchLocations: async () => {
|
fetchLocations: async () => {
|
||||||
set({ loading: true, error: null });
|
set({loading: true, error: null});
|
||||||
try {
|
try {
|
||||||
const data = await api.listLocations();
|
const data = await api.listLocations();
|
||||||
set({ locations: data, loading: false });
|
set({locations: data, loading: false});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
set({ error, loading: false });
|
set({error, loading: false});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addLocation: async (location) => {
|
addLocation: async (location) => {
|
||||||
set({ loading: true, error: null });
|
set({loading: true, error: null});
|
||||||
try {
|
try {
|
||||||
const newLoc = await api.addLocation(location);
|
const newLoc = await api.addLocation(location);
|
||||||
const normalizedLoc = {
|
const normalizedLoc = {
|
||||||
@@ -30,13 +30,13 @@ addLocation: async (location) => {
|
|||||||
}));
|
}));
|
||||||
return normalizedLoc;
|
return normalizedLoc;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
set({ error, loading: false });
|
set({error, loading: false});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updateLocation: async (id, location) => {
|
updateLocation: async (id, location) => {
|
||||||
set({ loading: true, error: null });
|
set({loading: true, error: null});
|
||||||
try {
|
try {
|
||||||
const updated = await api.updateLocation(id, location);
|
const updated = await api.updateLocation(id, location);
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
@@ -49,30 +49,35 @@ addLocation: async (location) => {
|
|||||||
|
|
||||||
return updated;
|
return updated;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
set({ error, loading: false });
|
set({error, loading: false});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteLocation: async (id) => {
|
deleteLocation: async (id) => {
|
||||||
set({ loading: true, error: null });
|
set({loading: true, error: null});
|
||||||
try {
|
try {
|
||||||
const deleted = await api.deleteLocation(id);
|
const deleted = await api.deleteLocation(id);
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
locations: state.locations.filter((loc) => loc.id !== id),
|
locations: state.locations.filter((loc) => loc.id !== id),
|
||||||
loading: false,
|
loading: false,
|
||||||
}));
|
}));
|
||||||
if(deleted) {
|
return deleted;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
set({ error, loading: false });
|
set({error, loading: false});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getLocation: (id) => {
|
getLocation: (id) => {
|
||||||
return get().locations.find((loc) => String(loc.id) === String(id));
|
const location = get().locations.find((loc) => String(loc.id) === String(id));
|
||||||
|
if (location && !location.imageSource) {
|
||||||
|
return {
|
||||||
|
...location,
|
||||||
|
imageSource: api.normalizeImageSource(location.image)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return location;
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user