Leon 1 rok pred
rodič
commit
d1fb446eb6

+ 11 - 0
src/app/time_of_day/index_time.scss

@@ -223,4 +223,15 @@
     color: #9E9E9E;
     font-size: 16px;
     line-height: 28px;
+}
+
+.history_item{
+    display: flex;
+    flex-direction: row;
+    align-items: center;
+    justify-content: space-between;
+    height: 96px;
+    margin-left: 66px;
+    margin-right: 66px;
+    border-bottom: solid 2px rgba(38, 38, 38, 0.2);
 }

+ 34 - 2
src/app/time_of_day/index_time.tsx

@@ -107,7 +107,10 @@ export default function IndexTimePage() {
         if (!current) {
             return
         }
-        jumpPage('','MyPlaces',navigation)
+        jumpPage('', 'MyPlaces', navigation, {
+            clearLocation: clearLocation,
+            changeLocation:changeLocation
+        })
     }
 
     function chooseLocation(res: any) {
@@ -120,7 +123,36 @@ export default function IndexTimePage() {
         })
     }
 
-    function saveLocation(location: any) {
+    async function saveLocation(location: any) {
+        Taro.setStorage({ key: 'lastLocation', data: JSON.stringify(location) })
+        var locations = await getStorage('locations')
+        var list: any = []
+        var isFind = false;
+        if (locations) {
+            list = JSON.parse(locations)
+        }
+
+        list.map(item => {
+            if (item.geo.lat == location.geo.lat && item.geo.lng == location.geo.lng) {
+                isFind = true
+            }
+        })
+
+        if (!isFind) {
+            list.push(location)
+        }
+
+        Taro.setStorage({ key: 'locations', data: JSON.stringify(list) })
+
+    }
+
+    function clearLocation() {
+        Taro.clearStorage()
+        setCurrent(null)
+    }
+
+    function changeLocation(location) {
+        setCurrent(location)
         Taro.setStorage({ key: 'lastLocation', data: JSON.stringify(location) })
     }
 

+ 110 - 3
src/app/time_of_day/my_places.tsx

@@ -1,7 +1,114 @@
-import { View } from "@tarojs/components";
+import { ScrollView, View, Text, Image } from "@tarojs/components";
+import Taro from "@tarojs/taro";
+import { useEffect, useState } from "react";
+import { useTranslation } from "react-i18next";
+import './index_time.scss'
+import { useNavigation, useRoute } from "@react-navigation/native";
+import showAlert from "@/components/basic/Alert";
 
-export default function MyPlacesPage(){
-    return <View>
+export default function MyPlacesPage() {
+    const [list, setList] = useState<any>([])
+    const { t } = useTranslation()
+    const navigation = useNavigation()
+    const router = useRoute()
+    const [current, setCurrent] = useState<any>(null)
 
+    useEffect(() => {
+        navigation.setOptions({
+            headerTitle: 'My Places',
+        });
+        getDatas()
+    }, [])
+
+    async function getDatas() {
+        var strLocation = await getStorage('lastLocation')
+        if (strLocation) {
+            setCurrent(JSON.parse(strLocation))
+        }
+
+        var locations = await getStorage('locations')
+        if (locations) {
+            setList(JSON.parse(locations))
+        }
+    }
+
+    async function getStorage(key: string) {
+        try {
+            const res = await Taro.getStorage({ key });
+            return res.data;
+        } catch {
+            return '';
+        }
+    }
+
+    function getLocation(current: any) {
+        if (current.geo) {
+            if (current.geo.city) {
+                return current.geo.city
+            }
+            if (current.geo.country) {
+                return current.geo.country
+            }
+        }
+        return t('time_of_day.index.unknown')
+    }
+
+    function clearAll() {
+        showAlert({
+            title: 'clear',
+            content: 'clear all',
+            showCancel: true,
+            confirm: () => {
+                if ((router.params! as any).clearLocation) {
+                    (router.params! as any).clearLocation()
+                }
+                navigation.goBack()
+            }
+        })
+    }
+
+    function isChecked(item) {
+        if (current && item.geo.lat == current.geo.lat && item.geo.lng == current.geo.lng){
+            return true
+        }
+        return false
+    }
+
+
+    return <View style={{ flex: 1, backgroundColor: '#fff' }}>
+        <ScrollView style={{ flex: 1 }}>
+            <View>
+                {
+                    list.map((item, index) => {
+                        return <View className="history_item" key={index} onClick={() => {
+                            if ((router.params! as any).changeLocation) {
+                                (router.params! as any).changeLocation(item)
+                            }
+                            navigation.goBack()
+                        }}>
+                            <Text style={{ color: '#262626', fontSize: 14 }}>{getLocation(item)}</Text>
+                            {
+                                isChecked(item) && <Image className="check" src={require('@assets/index_time/check.png')} />
+                            }
+
+                        </View>
+                    })
+                }
+                <View
+                    onClick={clearAll}
+                    style={{
+                        alignItems: 'center',
+                        justifyContent: 'center',
+                        marginTop: 15,
+                        marginBottom: 15,
+                        paddingTop: 15,
+                        paddingBottom: 15,
+                        paddingLeft: 50,
+                        paddingRight: 50
+                    }}>
+                    <Text style={{ color: '#FA5151', fontWeight: 'bold' }}>Clear All</Text>
+                </View>
+            </View>
+        </ScrollView>
     </View>
 }

+ 4 - 1
src/pages/map/map.tsx

@@ -32,7 +32,10 @@ export default function map() {
             })
         }
         else {
-            getCurrent()
+            // getCurrent()
+            setTimeout(()=>{
+                getCurrent()
+            },100)
         }
 
         navigation.setOptions({