lodアドレス追加に伴うお気に入り機能のマイグレーション
This commit is contained in:
parent
ff9faf939e
commit
bbc7db6e69
@ -1,11 +1,13 @@
|
|||||||
import React, { FC, useEffect } from "react";
|
import React, { FC, useEffect } from "react";
|
||||||
import { Text } from "react-native";
|
import { Text } from "react-native";
|
||||||
|
import { useFavoriteStation } from "../../stateBox/useFavoriteStation";
|
||||||
type Props = {
|
type Props = {
|
||||||
currentStation: any[];
|
currentStation: any[];
|
||||||
isMatsuyama: boolean;
|
isMatsuyama: boolean;
|
||||||
};
|
};
|
||||||
export const AddressText: FC<Props> = (props) => {
|
export const AddressText: FC<Props> = (props) => {
|
||||||
const { currentStation, isMatsuyama } = props;
|
const { currentStation, isMatsuyama } = props;
|
||||||
|
const {lodAddMigration} = useFavoriteStation();
|
||||||
const [stationAddress, setStationAddress] = React.useState("");
|
const [stationAddress, setStationAddress] = React.useState("");
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!!currentStation[0].jslodApi) {
|
if (!!currentStation[0].jslodApi) {
|
||||||
@ -18,6 +20,8 @@ export const AddressText: FC<Props> = (props) => {
|
|||||||
][0]["value"];
|
][0]["value"];
|
||||||
setStationAddress(c);
|
setStationAddress(c);
|
||||||
});
|
});
|
||||||
|
}else{
|
||||||
|
lodAddMigration();
|
||||||
}
|
}
|
||||||
}, [currentStation]);
|
}, [currentStation]);
|
||||||
return (
|
return (
|
||||||
|
@ -6,9 +6,11 @@ import React, {
|
|||||||
useLayoutEffect,
|
useLayoutEffect,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { AS } from "../storageControl";
|
import { AS } from "../storageControl";
|
||||||
|
import { useStationList } from "./useStationList";
|
||||||
const initialState = {
|
const initialState = {
|
||||||
favoriteStation: [],
|
favoriteStation: [],
|
||||||
setFavoriteStation: () => {},
|
setFavoriteStation: () => {},
|
||||||
|
lodAddMigration: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const FavoriteStationContext = createContext(initialState);
|
const FavoriteStationContext = createContext(initialState);
|
||||||
@ -19,6 +21,13 @@ export const useFavoriteStation = () => {
|
|||||||
|
|
||||||
export const FavoriteStationProvider = ({ children }) => {
|
export const FavoriteStationProvider = ({ children }) => {
|
||||||
const [favoriteStation, setFavoriteStation] = useState([]);
|
const [favoriteStation, setFavoriteStation] = useState([]);
|
||||||
|
const { getStationData } = useStationList();
|
||||||
|
const lodAddMigration = () => {
|
||||||
|
const migration = favoriteStation.map((d) => {
|
||||||
|
return getStationData(d[0].Station_JP);
|
||||||
|
});
|
||||||
|
setFavoriteStation(migration);
|
||||||
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
AS.getItem("favoriteStation")
|
AS.getItem("favoriteStation")
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
@ -29,7 +38,7 @@ export const FavoriteStationProvider = ({ children }) => {
|
|||||||
}, []);
|
}, []);
|
||||||
return (
|
return (
|
||||||
<FavoriteStationContext.Provider
|
<FavoriteStationContext.Provider
|
||||||
value={{ favoriteStation, setFavoriteStation }}
|
value={{ favoriteStation, setFavoriteStation, lodAddMigration }}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</FavoriteStationContext.Provider>
|
</FavoriteStationContext.Provider>
|
||||||
|
@ -12,10 +12,12 @@ import { getStationList } from "../lib/getStationList";
|
|||||||
type initialStateType = {
|
type initialStateType = {
|
||||||
originalStationList: any[];
|
originalStationList: any[];
|
||||||
setOriginalStationList: React.Dispatch<React.SetStateAction<any[]>>;
|
setOriginalStationList: React.Dispatch<React.SetStateAction<any[]>>;
|
||||||
|
getStationData: (id: string) => void;
|
||||||
};
|
};
|
||||||
const initialState = {
|
const initialState = {
|
||||||
originalStationList: [],
|
originalStationList: [],
|
||||||
setOriginalStationList: () => {},
|
setOriginalStationList: () => {},
|
||||||
|
getStationData: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const StationListContext = createContext<initialStateType>(initialState);
|
const StationListContext = createContext<initialStateType>(initialState);
|
||||||
@ -31,10 +33,22 @@ export const StationListProvider: FC<Props> = ({ children }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getStationList().then(setOriginalStationList);
|
getStationList().then(setOriginalStationList);
|
||||||
}, []);
|
}, []);
|
||||||
|
const getStationData: (name: string) => void = (name) => {
|
||||||
|
const returnArray = [];
|
||||||
|
Object.keys(originalStationList).forEach((key) => {
|
||||||
|
originalStationList[key].forEach((station) => {
|
||||||
|
if (station.Station_JP === name) {
|
||||||
|
if(!!station.jslodApi)returnArray.push(station);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return returnArray;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StationListContext.Provider
|
<StationListContext.Provider
|
||||||
value={{ originalStationList, setOriginalStationList }}
|
value={{ originalStationList, setOriginalStationList, getStationData }}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</StationListContext.Provider>
|
</StationListContext.Provider>
|
||||||
|
Loading…
Reference in New Issue
Block a user