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