31 lines
881 B
TypeScript
31 lines
881 B
TypeScript
import { useState } from 'react';
|
|
import { openBackTrainInfo } from '@/lib/eachTrainInfoCoreLib/openBackTrainInfo';
|
|
|
|
export const useExtendedStations = (trainData, setTrainData) => {
|
|
const [showHeadStation, setShowHeadStation] = useState([]);
|
|
const [showTailStation, setShowTailStation] = useState([]);
|
|
|
|
const extendToHeadStation = (station, dia, index) => {
|
|
const array = openBackTrainInfo(station, trainData, dia);
|
|
if (!array) return;
|
|
|
|
setTrainData(array);
|
|
setShowHeadStation((prev) => [...prev, index]);
|
|
};
|
|
|
|
const extendToTailStation = (station, dia, index) => {
|
|
const array = openBackTrainInfo(station, trainData, dia);
|
|
if (!array) return;
|
|
|
|
setTrainData(array);
|
|
setShowTailStation((prev) => [...prev, index]);
|
|
};
|
|
|
|
return {
|
|
showHeadStation,
|
|
showTailStation,
|
|
extendToHeadStation,
|
|
extendToTailStation,
|
|
};
|
|
};
|