Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#689 Fix numerous bugs #690

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="robots" content="noindex" />
<meta name="description" content="Rail Map Generator" />
Expand Down
236 changes: 118 additions & 118 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
},
"license": "GPL-3.0-only",
"dependencies": {
"@chakra-ui/react": "2.10.4",
"@chakra-ui/react": "2.10.5",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@railmapgen/rmg-components": "^10.1.9",
"@railmapgen/rmg-palette-resources": "^2.2.5",
"@railmapgen/rmg-runtime": "^10.3.2",
"@railmapgen/rmg-translate": "^3.2.3",
"@railmapgen/svg-assets": "^5.0.12",
"@reduxjs/toolkit": "^2.5.0",
"@reduxjs/toolkit": "^2.5.1",
"ag-grid-community": "^33.0.4",
"ag-grid-react": "^33.0.4",
"framer-motion": "^11.18.1",
"framer-motion": "^11.18.2",
"jszip": "^3.10.1",
"nanoid": "^5.0.9",
"react": "^18.3.1",
Expand Down Expand Up @@ -46,7 +46,7 @@
"prettier": "^3.4.2",
"terser": "^5.37.0",
"typescript": "^5.7.3",
"typescript-eslint": "^8.21.0",
"typescript-eslint": "^8.22.0",
"vite": "^6.0.11",
"vitest": "^3.0.4"
},
Expand Down
40 changes: 23 additions & 17 deletions src/components/ag-grid/station-ag-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import {
ColDef,
ModuleRegistry,
provideGlobalGridOptions,
RowSelectionOptions,
SelectionChangedEvent,
} from 'ag-grid-community';
import { RmgStyle, SidePanelMode, StationInfo, StationTransfer } from '../../constants/constants';
import { RmgStyle, SidePanelMode, StationInfo } from '../../constants/constants';
import { useTranslation } from 'react-i18next';
import { HStack } from '@chakra-ui/react';
import { setIsShareTrackEnabled, setSelectedStation, setSidePanelMode } from '../../redux/app/app-slice';
import { getRowSpanForColine } from '../../redux/param/coline-action';
import GzmtrStationCode from './gzmtr-station-code';
import { MonoColour } from '@railmapgen/rmg-palette-resources';
import { Translation } from '@railmapgen/rmg-translate';

// Register all community features
ModuleRegistry.registerModules([AllCommunityModule]);
Expand All @@ -30,6 +30,12 @@ interface StationAgGridProps {

type RowDataType = StationInfo & { id: string; rowSpan: [number, string | undefined] };

const rowSelection: RowSelectionOptions = {
mode: 'singleRow',
checkboxes: false,
enableClickSelection: true,
};

export default function StationAgGrid(props: StationAgGridProps) {
const { branchIndex } = props;
const { t, i18n } = useTranslation();
Expand Down Expand Up @@ -75,19 +81,19 @@ export default function StationAgGrid(props: StationAgGridProps) {
field: 'localisedName',
valueFormatter: ({ value, data }) =>
value.zh +
(style === RmgStyle.GZMTR && data?.currentLocalisedSecondaryName?.zh
? ` (${data.currentLocalisedSecondaryName.zh})`
(style === RmgStyle.GZMTR && data?.localisedSecondaryName?.zh
? ` (${data.localisedSecondaryName.zh})`
: ''),
},
{
headerName: t('English name'),
field: 'localisedName',
cellRenderer: ({ value, data }: { value: Translation; data: RowDataType }) => (
// field: 'localisedName',
cellRenderer: ({ data }: { data: RowDataType }) => (
<RmgMultiLineString
text={
value.en +
(style === RmgStyle.GZMTR && data.currentLocalisedSecondaryName?.en
? ` (${data.currentLocalisedSecondaryName.en})`
data.localisedName.en +
(style === RmgStyle.GZMTR && data.localisedSecondaryName?.en
? ` (${data.localisedSecondaryName.en})`
: '')
}
/>
Expand All @@ -96,10 +102,10 @@ export default function StationAgGrid(props: StationAgGridProps) {
},
{
headerName: t('StationAgGrid.interchange'),
field: 'transfer',
cellRenderer: ({ value }: { value: StationTransfer }) => (
// field: 'transfer',
cellRenderer: ({ data }: { data: RowDataType }) => (
<HStack>
{value.groups
{data.transfer.groups
.map(group => group.lines ?? [])
.flat()
.map((it, i) => (
Expand All @@ -116,14 +122,14 @@ export default function StationAgGrid(props: StationAgGridProps) {
},
{
headerName: t('StationAgGrid.coline'),
field: 'rowSpan',
// field: 'rowSpan',
rowSpan: ({ data }) => data?.rowSpan[0] ?? 0,
cellClassRules: {
'rmg-ag-grid--spanned-cell': ({ value }) => value[0] > 0,
'rmg-ag-grid--spanned-cell': ({ data }) => !!data && data.rowSpan[0] > 0,
},
cellRenderer: ({ value }: { value: RowDataType['rowSpan'] }) => (
cellRenderer: ({ data }: { data: RowDataType }) => (
<HStack>
{coline[value[1] as string]?.colors?.map((it, i) => (
{coline[data.rowSpan[1] as string]?.colors?.map((it, i) => (
<RmgLineBadge key={i} name={[it[4], it[5]]} bg={it[2]} fg={it[3]} showShortName />
))}
</HStack>
Expand Down Expand Up @@ -182,7 +188,7 @@ export default function StationAgGrid(props: StationAgGridProps) {
suppressCellFocus={true}
suppressMovableColumns={true}
suppressRowTransform={true}
rowSelection={'single'}
rowSelection={rowSelection}
onSelectionChanged={handleSelectionChanged}
onGridReady={handleGridReady}
debug={import.meta.env.DEV}
Expand Down
12 changes: 6 additions & 6 deletions src/components/side-panel/station-side-panel/info-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function InfoSection() {
const selectedStation = useRootSelector(state => state.app.selectedStation);
console.log('InfoSection:: Rendering for', selectedStation);
const style = useRootSelector(state => state.param.style);
const { num, localisedName, currentLocalisedSecondaryName } = useRootSelector(
const { num, localisedName, localisedSecondaryName } = useRootSelector(
state => state.param.stn_list[selectedStation]
);

Expand Down Expand Up @@ -53,7 +53,7 @@ export default function InfoSection() {
{ label: t('No'), value: false },
] as { label: string; value: boolean }[]
}
defaultValue={!!currentLocalisedSecondaryName}
defaultValue={!!localisedSecondaryName}
onChange={flag => dispatch(toggleStationSecondaryName(selectedStation, flag))}
/>
),
Expand All @@ -62,18 +62,18 @@ export default function InfoSection() {
{
type: 'input',
label: t('StationSidePanel.info.zhSecondary'),
value: currentLocalisedSecondaryName?.zh ?? '',
value: localisedSecondaryName?.zh ?? '',
placeholder: '1号航站楼',
onChange: (value: string) => dispatch(updateStationSecondaryName(selectedStation, 'zh', value)),
hidden: !currentLocalisedSecondaryName || ![RmgStyle.GZMTR].includes(style),
hidden: !localisedSecondaryName || ![RmgStyle.GZMTR].includes(style),
},
{
type: 'input',
label: t('StationSidePanel.info.enSecondary'),
value: currentLocalisedSecondaryName?.en ?? '',
value: localisedSecondaryName?.en ?? '',
placeholder: 'Terminal 1',
onChange: (value: string) => dispatch(updateStationSecondaryName(selectedStation, 'en', value)),
hidden: !currentLocalisedSecondaryName || ![RmgStyle.GZMTR].includes(style),
hidden: !localisedSecondaryName || ![RmgStyle.GZMTR].includes(style),
},
];

Expand Down
2 changes: 1 addition & 1 deletion src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export interface StationInfo {
// name?: Name;
// secondaryName?: Name;
localisedName: Translation;
currentLocalisedSecondaryName?: Translation;
localisedSecondaryName?: Translation;
/**
* Station number. (GZMTR specific)
*/
Expand Down
6 changes: 3 additions & 3 deletions src/redux/param/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ export const updateStationName = (stationId: string, lang: LanguageCode, value:

export const toggleStationSecondaryName = (stationId: string, flag: boolean) => {
return (dispatch: RootDispatch, getState: () => RootState) => {
const { currentLocalisedSecondaryName, ...stationInfo } = getState().param.stn_list[stationId];
const { localisedSecondaryName, ...stationInfo } = getState().param.stn_list[stationId];
if (flag) {
dispatch(setStation(stationId, { ...stationInfo, currentLocalisedSecondaryName: {} }));
dispatch(setStation(stationId, { ...stationInfo, localisedSecondaryName: {} }));
} else {
dispatch(setStation(stationId, stationInfo));
}
Expand All @@ -210,7 +210,7 @@ export const updateStationSecondaryName = (stationId: string, lang: LanguageCode
dispatch(
setStation(stationId, {
...stationInfo,
currentLocalisedSecondaryName: { ...stationInfo.currentLocalisedSecondaryName, [lang]: value },
localisedSecondaryName: { ...stationInfo.localisedSecondaryName, [lang]: value },
})
);
};
Expand Down
12 changes: 6 additions & 6 deletions src/svgs/gzmtr/info-gzmtr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const InfoGZMTR = () => {
stn_list: stationList,
} = useRootSelector(store => store.param);
const curStnInfo = stationList[currentStationIndex];
const { localisedName, currentLocalisedSecondaryName } = curStnInfo;
const { localisedName, localisedSecondaryName } = curStnInfo;

const [nameBBox, setNameBBox] = useState({ width: 0 } as SVGRect);

Expand All @@ -38,22 +38,22 @@ const InfoGZMTR = () => {
const transforms = {
nameGroup: {
x: svgWidths.runin / 2,
y: 0.5 * svgHeight - 50 - (enNameRows - 1) * 18 - (currentLocalisedSecondaryName ? 29 : 0),
y: 0.5 * svgHeight - 50 - (enNameRows - 1) * 18 - (localisedSecondaryName ? 29 : 0),
},
secondaryName: {
x: 0,
y: 70 + enNameRows * 36,
},
stationNumber: {
x: stationNumberX,
y: 0.5 * svgHeight - 30 - (enNameRows - 1) * 18 - (currentLocalisedSecondaryName ? 58 / 2 : 0),
y: 0.5 * svgHeight - 30 - (enNameRows - 1) * 18 - (localisedSecondaryName ? 58 / 2 : 0),
},
stationNumberPost2022: {
x:
direction === ShortDirection.left
? stationNumberX
: (svgWidths[CanvasType.RunIn] - nameBBox.width) / 2 - NAME_NUM_GAP,
y: 0.5 * svgHeight - (enNameRows - 2) * 18 - (currentLocalisedSecondaryName ? 58 / 2 : 0),
y: 0.5 * svgHeight - (enNameRows - 2) * 18 - (localisedSecondaryName ? 58 / 2 : 0),
},
};

Expand All @@ -67,9 +67,9 @@ const InfoGZMTR = () => {
sparse={infoPanelType === PanelTypeGZMTR.gz11}
onUpdate={setNameBBox}
/>
{currentLocalisedSecondaryName && (
{localisedSecondaryName && (
<CurrentStationSecondaryName
secondaryName={currentLocalisedSecondaryName}
secondaryName={localisedSecondaryName}
transform={`translate(${transforms.secondaryName.x},${transforms.secondaryName.y})`}
/>
)}
Expand Down
6 changes: 3 additions & 3 deletions src/svgs/gzmtr/runin/next-station.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type NextStationProps = {
export default function NextStation({ nextId, nameBBox, ignoreNumWidth }: NextStationProps) {
const { svgWidth: svgWidths, svg_height: svgHeight, direction } = useRootSelector(store => store.param);
const nextInfo = useRootSelector(store => store.param.stn_list[nextId]);
const { localisedName, currentLocalisedSecondaryName } = nextInfo;
const { localisedName, localisedSecondaryName } = nextInfo;
const { zh: zhName = '', en: enName = '' } = localisedName;
const svgWidth = svgWidths[CanvasType.RunIn];

Expand Down Expand Up @@ -84,10 +84,10 @@ export default function NextStation({ nextId, nameBBox, ignoreNumWidth }: NextSt
))}
</g>
</g>
{currentLocalisedSecondaryName && (
{localisedSecondaryName && (
<g textAnchor="middle" transform={`translate(${transforms.nextName.x},0)`}>
<NextStationSecondary
secName={currentLocalisedSecondaryName}
secName={localisedSecondaryName}
transform={`translate(${nextBBox.width / 2},${30 + enName.split('\\').length * 17 + 5})`}
/>
</g>
Expand Down
7 changes: 2 additions & 5 deletions src/svgs/gzmtr/runin/next-via-stations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function NextViaStations({ nameBBox }: NextViaStationsProps) {

const {
localisedName: { en: currentEnName = '' },
currentLocalisedSecondaryName,
localisedSecondaryName,
} = stationList[currentStation];
const {
localisedName: { zh: zhName = '', en: enName = '' },
Expand All @@ -66,10 +66,7 @@ export default function NextViaStations({ nameBBox }: NextViaStationsProps) {
(svgWidth * COACH_NUMBER_X_PERCENTAGE - COACH_NUMBER_WIDTH / 2)) /
2 +
(ARROW_WIDTH * LOOP_NEXT_ARROW_SCALE) / 2,
y:
0.5 * svgHeight -
(currentEnName.split('\\').length - 2) * 18 -
(currentLocalisedSecondaryName ? 58 / 2 : 0),
y: 0.5 * svgHeight - (currentEnName.split('\\').length - 2) * 18 - (localisedSecondaryName ? 58 / 2 : 0),
rotate: direction === ShortDirection.left ? 0 : 180,
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/svgs/gzmtr/station.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function Station(props: Props) {
if (stationNameEl.current) {
setNameBBox(stationNameEl.current.getBBox());
}
}, [stationNameEl.current, stnY, stnInfo.localisedName, stnInfo.currentLocalisedSecondaryName, stnInfo.services]);
}, [stationNameEl.current, stnY, stnInfo.localisedName, stnInfo.localisedSecondaryName, stnInfo.services]);

const isNameShift = stnInfo.parents.length === 2 || stnInfo.children.length === 2;
const tickRotation =
Expand Down Expand Up @@ -89,7 +89,7 @@ export default function Station(props: Props) {
<g ref={stationNameEl} transform={`translate(${-nameDX},0)`}>
<StationNameWrapper
primaryName={stnInfo.localisedName}
secondaryName={stnInfo.currentLocalisedSecondaryName}
secondaryName={stnInfo.localisedSecondaryName}
stationState={stnState}
flipped={tickRotation === 180}
express={stnInfo.services.includes(Services.express)}
Expand Down