SignをID管理ベースに置き換え
This commit is contained in:
parent
3b98882d80
commit
ac06ca6c75
@ -91,7 +91,7 @@ export const StationDeteilView = (props) => {
|
||||
{currentStation && (
|
||||
<View style={{ margin: 10, marginHorizontal: wp("10%") }}>
|
||||
<Sign
|
||||
currentStation={currentStation}
|
||||
stationID={currentStation[0].StationNumber}
|
||||
oP={() => {
|
||||
usePDFView == "true"
|
||||
? Linking.openURL(currentStation[0].StationTimeTable)
|
||||
|
@ -78,7 +78,7 @@ export const CarouselBox = ({
|
||||
>
|
||||
<View style={{ flex: 1 }} />
|
||||
<Sign
|
||||
currentStation={item}
|
||||
stationID={item[0].StationNumber}
|
||||
isCurrentStation={item == currentStation}
|
||||
oP={oPSign}
|
||||
oLP={oLPSign}
|
||||
|
@ -15,7 +15,12 @@ import { AddressText } from "./AddressText";
|
||||
import { useStationList } from "../../stateBox/useStationList";
|
||||
|
||||
export default function Sign(props) {
|
||||
const { currentStation, oP, oLP, isCurrentStation = false } = props;
|
||||
const { oP, oLP, isCurrentStation = false, stationID } = props;
|
||||
const { getStationDataFromId } = useStationList();
|
||||
if (!stationID) {
|
||||
return <></>;
|
||||
}
|
||||
const [currentStationData] = useState(getStationDataFromId(stationID));
|
||||
const { favoriteStation, setFavoriteStation } = useFavoriteStation();
|
||||
const [nexPrePosition, setNexPrePosition] = useState(0);
|
||||
const { originalStationList } = useStationList();
|
||||
@ -26,48 +31,40 @@ export default function Sign(props) {
|
||||
useLayoutEffect(() => {
|
||||
const isFavorite = favoriteStation.filter((d) => {
|
||||
const compare = JSON.stringify(d);
|
||||
const current = JSON.stringify(currentStation);
|
||||
if (compare === current) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
const current = JSON.stringify(currentStationData);
|
||||
return compare === current;
|
||||
});
|
||||
setTestButtonStatus(isFavorite.length == 0 ? false : true);
|
||||
}, [favoriteStation, currentStation]);
|
||||
}, [favoriteStation, currentStationData]);
|
||||
useEffect(() => {
|
||||
const isFavorite = favoriteStation.filter((d) => {
|
||||
const compare = JSON.stringify(d);
|
||||
const current = JSON.stringify(currentStation);
|
||||
if (compare === current) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
const current = JSON.stringify(currentStationData);
|
||||
return compare === current;
|
||||
});
|
||||
setTestButtonStatus(isFavorite.length == 0 ? false : true);
|
||||
}, [favoriteStation, currentStation]);
|
||||
}, [favoriteStation, currentStationData]);
|
||||
|
||||
useInterval(() => {
|
||||
if (currentStation.length == 1) {
|
||||
if (currentStationData.length == 1) {
|
||||
setNexPrePosition(0);
|
||||
return () => {};
|
||||
}
|
||||
setNexPrePosition(
|
||||
nexPrePosition + 1 == currentStation.length ? 0 : nexPrePosition + 1
|
||||
nexPrePosition + 1 == currentStationData.length ? 0 : nexPrePosition + 1
|
||||
);
|
||||
}, 2000);
|
||||
|
||||
useEffect(() => {
|
||||
setNexPrePosition(0);
|
||||
getPreNextStation(currentStation[0]);
|
||||
if (currentStation.length == 1) return () => {};
|
||||
getPreNextStation(currentStation[1]);
|
||||
}, [currentStation]);
|
||||
getPreNextStation(currentStationData[0]);
|
||||
if (currentStationData.length == 1) return () => {};
|
||||
getPreNextStation(currentStationData[1]);
|
||||
}, [currentStationData]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentStation[nexPrePosition]) return () => {};
|
||||
getPreNextStation(currentStation[nexPrePosition]);
|
||||
if (!currentStationData[nexPrePosition]) return () => {};
|
||||
getPreNextStation(currentStationData[nexPrePosition]);
|
||||
}, [nexPrePosition]);
|
||||
const getPreNextStation = (now) => {
|
||||
const lineList = [
|
||||
@ -101,20 +98,20 @@ export default function Sign(props) {
|
||||
if (returnData[1]) setNexStation(returnData[1]);
|
||||
}
|
||||
};
|
||||
const isMatsuyama = currentStation[0].StationNumber == "Y55";
|
||||
const isMatsuyama = currentStationData[0].StationNumber == "Y55";
|
||||
//const isMatsuyama = true;
|
||||
const favoliteChanger = () => {
|
||||
if (testButtonStatus) {
|
||||
const otherData = favoriteStation.filter((d) => {
|
||||
const compare = JSON.stringify(d);
|
||||
const current = JSON.stringify(currentStation);
|
||||
const current = JSON.stringify(currentStationData);
|
||||
return compare !== current;
|
||||
});
|
||||
AS.setItem("favoriteStation", JSON.stringify(otherData));
|
||||
setFavoriteStation(otherData);
|
||||
} else {
|
||||
let ret = favoriteStation;
|
||||
ret.push(currentStation);
|
||||
ret.push(currentStationData);
|
||||
AS.setItem("favoriteStation", JSON.stringify(ret));
|
||||
setFavoriteStation(ret);
|
||||
}
|
||||
@ -138,8 +135,12 @@ export default function Sign(props) {
|
||||
source={require("../../assets/StationSign.json")}
|
||||
/>
|
||||
)}
|
||||
<StationNumberMaker {...{ currentStation, isMatsuyama }} />
|
||||
<StationNameArea {...{ currentStation, isMatsuyama }} />
|
||||
<StationNumberMaker
|
||||
{...{ currentStation: currentStationData, isMatsuyama }}
|
||||
/>
|
||||
<StationNameArea
|
||||
{...{ currentStation: currentStationData, isMatsuyama }}
|
||||
/>
|
||||
{isCurrentStation ? (
|
||||
<View style={{ position: "absolute", right: 0, top: 0 }}>
|
||||
<MaterialCommunityIcons
|
||||
@ -163,7 +164,7 @@ export default function Sign(props) {
|
||||
<View style={styleSheet[isMatsuyama ? "下帯内容B" : "下帯内容"]}>
|
||||
<NextPreStationLine {...{ nexStation, preStation, isMatsuyama }} />
|
||||
</View>
|
||||
<AddressText {...{ currentStation, isMatsuyama }} />
|
||||
<AddressText {...{ currentStation: currentStationData, isMatsuyama }} />
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}
|
||||
|
2
menu.js
2
menu.js
@ -82,7 +82,6 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
||||
let returnDataBase = lineList
|
||||
.map((d) => findStationEachLine(originalStationList[d]))
|
||||
.filter((d) => {
|
||||
console.log(d);
|
||||
return d.length > 0})
|
||||
.reduce((pre, current) => {
|
||||
pre.push(...current);
|
||||
@ -135,7 +134,6 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
||||
}, [selectedCurrentStation]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(selectedCurrentStation);
|
||||
if (allStationData.length == 0) return;
|
||||
if (allStationData[selectedCurrentStation] == undefined) return;
|
||||
const { lat, lng } =
|
||||
|
@ -29,10 +29,10 @@ type Props = {
|
||||
};
|
||||
export const FavoriteStationProvider:FC<Props> = ({ children }) => {
|
||||
const [favoriteStation, setFavoriteStation] = useState([]);
|
||||
const { getStationData } = useStationList();
|
||||
const { getStationDataFromName } = useStationList();
|
||||
const lodAddMigration = () => {
|
||||
const migration = favoriteStation.map((d) => {
|
||||
return getStationData(d[0].Station_JP);
|
||||
return getStationDataFromName(d[0].Station_JP);
|
||||
});
|
||||
setFavoriteStation(migration);
|
||||
};
|
||||
|
@ -10,13 +10,15 @@ import { lineList, getStationList } from "../lib/getStationList";
|
||||
type initialStateType = {
|
||||
originalStationList: any[][];
|
||||
setOriginalStationList: React.Dispatch<React.SetStateAction<any[]>>;
|
||||
getStationData: (id: string) => void;
|
||||
getStationDataFromName: (id: string) => any[];
|
||||
getStationDataFromId: (id: string) => any[];
|
||||
stationList: any[];
|
||||
};
|
||||
const initialState = {
|
||||
originalStationList: [[]],
|
||||
setOriginalStationList: () => {},
|
||||
getStationData: () => {},
|
||||
getStationDataFromName: () => [],
|
||||
getStationDataFromId: () => [],
|
||||
stationList: [],
|
||||
};
|
||||
|
||||
@ -33,7 +35,19 @@ export const StationListProvider: FC<Props> = ({ children }) => {
|
||||
useEffect(() => {
|
||||
getStationList().then(setOriginalStationList);
|
||||
}, []);
|
||||
const getStationData: (name: string) => void = (name) => {
|
||||
const getStationDataFromId: (id: string) => any[] = (id) => {
|
||||
console.log("id", id);
|
||||
let returnArray = [];
|
||||
Object.keys(originalStationList).forEach((key) => {
|
||||
originalStationList[key].forEach((station) => {
|
||||
if (station.StationNumber === id) {
|
||||
returnArray = [...returnArray, ...getStationDataFromName(station.Station_JP)];
|
||||
}
|
||||
});
|
||||
});
|
||||
return returnArray;
|
||||
};
|
||||
const getStationDataFromName: (name: string) => any[] = (name) => {
|
||||
const returnArray = [];
|
||||
Object.keys(originalStationList).forEach((key) => {
|
||||
originalStationList[key].forEach((station) => {
|
||||
@ -59,7 +73,7 @@ export const StationListProvider: FC<Props> = ({ children }) => {
|
||||
|
||||
return (
|
||||
<StationListContext.Provider
|
||||
value={{ originalStationList, setOriginalStationList, getStationData, stationList }}
|
||||
value={{ originalStationList, setOriginalStationList, getStationDataFromName, getStationDataFromId, stationList }}
|
||||
>
|
||||
{children}
|
||||
</StationListContext.Provider>
|
||||
|
Loading…
Reference in New Issue
Block a user