Naprawiono poprawne wyświetlanie zdjęcia od razu po dodaniu.

NORMALIZACJA ZDJECIA JEST NAJWAŻNIESZA
This commit is contained in:
2025-05-23 21:19:11 +02:00
parent f22de8150d
commit 9d253c4c86
4 changed files with 28 additions and 22 deletions

View File

@@ -19,7 +19,7 @@ export async function listLocations() {
}
}
const normalizeImageSource = (image) => {
export const normalizeImageSource = (image) => {
if (!image) return null;
if (typeof image === 'string') {

View File

@@ -212,7 +212,7 @@ export default function FormScreen() {
placeholder="Wpisz powierzchnię"
style={{margin: 10, width: "100%"}}
value={formData.area}
keyboardType="numeric"
keyboardType="numbers-and-punctuation"
onChangeText={(e) => setFormData({...formData, area: e})}
/>
<TextInput

View File

@@ -65,6 +65,8 @@ export default function EditLocation() {
image: formData.image,
area: parseFloat(formData.area),
population: parseInt(formData.population, 10),
longitude: parseFloat(formData.longitude),
latitude: parseFloat(formData.latitude),
});
if (response) {
@@ -142,7 +144,7 @@ export default function EditLocation() {
placeholder="Wpisz powierzchnię"
style={{margin: 10, width: "100%"}}
value={formData.area}
keyboardType="numeric"
keyboardType="numbers-and-punctuation"
onChangeText={(e) => setFormData({...formData, area: e})}
/>
<TextInput
@@ -160,7 +162,7 @@ export default function EditLocation() {
placeholder="Wpisz długość geograficzną"
style={{margin: 10, width: "100%"}}
value={formData.longitude}
keyboardType="numeric"
keyboardType="numbers-and-punctuation"
onChangeText={(e) => setFormData({...formData, longitude: e})}
/>
<TextInput
@@ -169,7 +171,7 @@ export default function EditLocation() {
placeholder="Wpisz szerokość geograficzną"
style={{margin: 10, width: "100%"}}
value={formData.latitude}
keyboardType="numeric"
keyboardType="numbers-and-punctuation"
onChangeText={(e) => setFormData({...formData, latitude: e})}
/>
<Button
@@ -187,9 +189,9 @@ export default function EditLocation() {
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#25292e",
justifyContent: "flex-start",
alignItems: "center",
flexGrow: 1,
},
});

View File

@@ -20,11 +20,15 @@ const useLocationStore = create((set, get) => ({
set({ loading: true, error: null });
try {
const newLoc = await api.addLocation(location);
const normalizedLoc = {
...newLoc,
imageSource: api.normalizeImageSource(newLoc.image)
};
set((state) => ({
locations: [...state.locations, newLoc],
locations: [...state.locations, normalizedLoc],
loading: false,
}));
return newLoc;
return normalizedLoc;
} catch (error) {
set({ error, loading: false });
return null;
@@ -37,7 +41,7 @@ const useLocationStore = create((set, get) => ({
const updated = await api.updateLocation(id, location);
set((state) => ({
locations: state.locations.map((loc) =>
loc.id == id ? updated : loc
loc.id === id ? updated : loc
),
loading: false,
@@ -55,7 +59,7 @@ const useLocationStore = create((set, get) => ({
try {
const deleted = await api.deleteLocation(id);
set((state) => ({
locations: state.locations.filter((loc) => loc.id != id),
locations: state.locations.filter((loc) => loc.id !== id),
loading: false,
}));
if(deleted) {