update demo-dictionary-app,
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import {
|
||||
IonButton,
|
||||
IonButtons,
|
||||
IonCard,
|
||||
IonCardContent,
|
||||
IonCardSubtitle,
|
||||
IonCardTitle,
|
||||
IonCol,
|
||||
IonContent,
|
||||
IonGrid,
|
||||
IonHeader,
|
||||
IonIcon,
|
||||
IonPage,
|
||||
@@ -11,54 +16,27 @@ import {
|
||||
IonToolbar,
|
||||
useIonRouter,
|
||||
} from '@ionic/react';
|
||||
import { bookOutline, chevronBackOutline, heart, search } from 'ionicons/icons';
|
||||
import { useStoreState } from 'pullstate';
|
||||
import { useRef } from 'react';
|
||||
import { WordStore } from '../store';
|
||||
import { getFavourites, getSearchCount } from '../store/Selectors';
|
||||
|
||||
import { Geolocation } from '@capacitor/geolocation';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { SkeletonDashboard } from '../components/SkeletonDashboard';
|
||||
import { chevronBackOutline, refreshOutline } from 'ionicons/icons';
|
||||
import { CurrentWeather } from '../components/CurrentWeather';
|
||||
|
||||
function Tab1() {
|
||||
const Tab1 = () => {
|
||||
const router = useIonRouter();
|
||||
|
||||
const [currentWeather, setCurrentWeather] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
getCurrentPosition();
|
||||
}, []);
|
||||
|
||||
const getCurrentPosition = async () => {
|
||||
setCurrentWeather(false);
|
||||
const coordinates = await Geolocation.getCurrentPosition();
|
||||
getAddress(coordinates.coords);
|
||||
};
|
||||
|
||||
const getAddress = async (coords) => {
|
||||
const query = `${coords.latitude},${coords.longitude}`;
|
||||
const response = await fetch(
|
||||
`https://api.weatherapi.com/v1/current.json?key=f93eb660b2424258bf5155016210712&q=${query}`
|
||||
);
|
||||
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
setCurrentWeather(data);
|
||||
};
|
||||
const pageRef = useRef();
|
||||
const favourites = useStoreState(WordStore, getFavourites);
|
||||
const searchCount = useStoreState(WordStore, getSearchCount);
|
||||
|
||||
function handleBackClick() {
|
||||
router.goBack();
|
||||
}
|
||||
|
||||
return (
|
||||
<IonPage>
|
||||
<IonPage ref={pageRef}>
|
||||
<IonHeader>
|
||||
<IonToolbar>
|
||||
<IonTitle>My Weather</IonTitle>
|
||||
|
||||
<IonButtons slot="end">
|
||||
<IonButton onClick={() => getCurrentPosition()}>
|
||||
<IonIcon icon={refreshOutline} color="primary" />
|
||||
</IonButton>
|
||||
</IonButtons>
|
||||
<IonTitle>Dashboard</IonTitle>
|
||||
|
||||
<IonButtons slot="start">
|
||||
<IonButton onClick={() => handleBackClick()}>
|
||||
@@ -71,25 +49,66 @@ function Tab1() {
|
||||
<IonHeader collapse="condense">
|
||||
<IonToolbar>
|
||||
<IonTitle size="large">Dashboard</IonTitle>
|
||||
|
||||
<IonButtons slot="start">
|
||||
<IonButton onClick={() => handleBackClick()}>
|
||||
<IonIcon icon={chevronBackOutline} color="primary" />
|
||||
</IonButton>
|
||||
</IonButtons>
|
||||
</IonToolbar>
|
||||
</IonHeader>
|
||||
|
||||
<IonRow className="ion-margin-start ion-margin-end ion-justify-content-center ion-text-center">
|
||||
<IonCol size="12">
|
||||
<h4>Here's your location based weather</h4>
|
||||
</IonCol>
|
||||
</IonRow>
|
||||
<IonGrid>
|
||||
<IonRow className={`animate__animated animate__faster animate__fadeIn`}>
|
||||
<IonCol size="12">
|
||||
<IonCard>
|
||||
<IonCardContent>
|
||||
<IonIcon icon={bookOutline} color="primary" style={{ fontSize: '2rem' }} />
|
||||
<IonCardTitle>Ionic Dictionary App</IonCardTitle>
|
||||
<p>Based on the English language</p>
|
||||
</IonCardContent>
|
||||
</IonCard>
|
||||
</IonCol>
|
||||
</IonRow>
|
||||
|
||||
<div style={{ marginTop: '-1.5rem' }}>
|
||||
{currentWeather ? (
|
||||
<CurrentWeather currentWeather={currentWeather} />
|
||||
) : (
|
||||
<SkeletonDashboard />
|
||||
)}
|
||||
</div>
|
||||
<IonRow className={`animate__animated animate__faster animate__fadeIn`}>
|
||||
<IonCol size="12">
|
||||
<IonCard>
|
||||
<IonCardContent>
|
||||
<IonCardTitle>Did you know?</IonCardTitle>
|
||||
<p>There are 171, 146 words in the English language!</p>
|
||||
<IonButton expand="block" className="ion-margin-top" routerLink="/search">
|
||||
Search now →
|
||||
</IonButton>
|
||||
</IonCardContent>
|
||||
</IonCard>
|
||||
</IonCol>
|
||||
</IonRow>
|
||||
|
||||
<IonRow className={`animate__animated animate__faster animate__fadeIn`}>
|
||||
<IonCol size="6">
|
||||
<IonCard routerLink="/favourites">
|
||||
<IonCardContent className="ion-text-center">
|
||||
<IonIcon icon={heart} color="primary" />
|
||||
<IonCardTitle>{favourites.length}</IonCardTitle>
|
||||
<IonCardSubtitle>Favourites</IonCardSubtitle>
|
||||
</IonCardContent>
|
||||
</IonCard>
|
||||
</IonCol>
|
||||
<IonCol size="6">
|
||||
<IonCard routerLink="/favourites">
|
||||
<IonCardContent className="ion-text-center">
|
||||
<IonIcon icon={search} color="primary" />
|
||||
<IonCardTitle>{searchCount}</IonCardTitle>
|
||||
<IonCardSubtitle>Searches</IonCardSubtitle>
|
||||
</IonCardContent>
|
||||
</IonCard>
|
||||
</IonCol>
|
||||
</IonRow>
|
||||
</IonGrid>
|
||||
</IonContent>
|
||||
</IonPage>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default Tab1;
|
||||
|
Reference in New Issue
Block a user