Skip to content

Commit

Permalink
Normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-vasconcelos committed Dec 5, 2023
1 parent 345778d commit cdac3d1
Show file tree
Hide file tree
Showing 21 changed files with 332 additions and 229 deletions.
3 changes: 3 additions & 0 deletions frontend/components/CopyBadge/CopyBadge.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* * */
/* CONTAINER */

.container {
display: flex;
align-items: center;
Expand Down
43 changes: 0 additions & 43 deletions frontend/components/LinePatternMap/LinePatternMap.js

This file was deleted.

25 changes: 0 additions & 25 deletions frontend/components/LinePatternMap/LinePatternMap.module.css

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import styles from './LinesExplorerContent.module.css';
import { useLinesExplorerContext } from '@/contexts/LinesExplorerContext';
import LinesExplorerContentHeader from '@/components/LinesExplorerContentHeader/LinesExplorerContentHeader';
import LinesExplorerContentPatternPath from '@/components/LinesExplorerContentPatternPath/LinesExplorerContentPatternPath';
import LinesExplorerContentPatternMap from '@/components/LinesExplorerContentPatternMap/LinesExplorerContentPatternMap';

/* * */

Expand All @@ -27,8 +28,8 @@ export default function LinesExplorerContent() {
linesExplorerContext?.entities?.line?.id && (
<div className={styles.container}>
<LinesExplorerContentHeader />
{linesExplorerContext?.entities?.pattern?.id && <LinesExplorerContentPatternPath />}
{/* <LinePatternMap /> */}
{linesExplorerContext.entities.pattern?.shape_id && <LinesExplorerContentPatternMap />}
{linesExplorerContext.entities.pattern?.id && <LinesExplorerContentPatternPath />}
</div>
)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use client';

/* * */

import useSWR from 'swr';
import { useTranslations } from 'next-intl';
import OSMMap from '@/components/OSMMap/OSMMap';
import styles from './LinesExplorerContentPatternMap.module.css';
import { useMap, Source, Layer } from 'react-map-gl/maplibre';
import { useLinesExplorerContext } from '@/contexts/LinesExplorerContext';

/* * */

export default function LinesExplorerContentPatternMap() {
//

//
// A. Setup variables

const { patternShapeMap } = useMap();
const t = useTranslations('LinesExplorerContentPatternMap');
const linesExplorerContext = useLinesExplorerContext();

//
// B. Fetch data

const { data: shapeData } = useSWR(linesExplorerContext.entities?.pattern?.shape_id && `https://api.carrismetropolitana.pt/shapes/${linesExplorerContext.entities.pattern.shape_id}`);

//
// C. Render components

return (
<div className={styles.container}>
<OSMMap id="patternShapeMap" scrollZoom={false} mapStyle="map">
{shapeData?.geojson && (
<Source id="pattern-shape" type="geojson" data={shapeData.geojson}>
<Layer id="pattern-shape" type="line" source="pattern-shape" layout={{ 'line-join': 'round', 'line-cap': 'round' }} paint={{ 'line-color': linesExplorerContext.entities?.pattern?.color ? linesExplorerContext.entities.pattern.color : '#000000', 'line-width': 4 }} />
</Source>
)}
</OSMMap>
</div>
);

//
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* * */
/* CONTAINER */

.container {
height: 400px;
width: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

/* * */

import useSWR from 'swr';
import { useTranslations } from 'next-intl';
import { useLineFormContext } from '@/forms/LineForm';
import styles from './LinesExplorerContentPatternPathStop.module.css';
import CopyBadge from '../CopyBadge/CopyBadge';
import LinePatternPathSpine from '../LinePatternPathSpine/LinePatternPathSpine';
import LinePatternPathTimetable from '../LinePatternPathTimetable/LinePatternPathTimetable';
import CopyBadge from '@/components/CopyBadge/CopyBadge';
import LinesExplorerContentPatternPathStopTimetable from '@/components/LinesExplorerContentPatternPathStopTimetable/LinesExplorerContentPatternPathStopTimetable';
import { useMemo, useState } from 'react';
import StopName from '../StopName/StopName';
import { Space } from '@mantine/core';
import StopPDF from '../StopPDF/StopPDF';
import StopRealTime from '../StopRealTime/StopRealTime';
import LiveIcon from '../LiveIcon/LiveIcon';
import Text from '../Text/Text';
import LinesExplorerContentPatternPathStopPdf from '@/components/LinesExplorerContentPatternPathStopPdf/LinesExplorerContentPatternPathStopPdf';
import Text from '@/components/Text/Text';
import LinesExplorerContentPatternPathStopRealtime from '@/components/LinesExplorerContentPatternPathStopRealtime/LinesExplorerContentPatternPathStopRealtime';
import LinesExplorerContentPatternPathStopSpine from '@/components/LinesExplorerContentPatternPathStopSpine/LinesExplorerContentPatternPathStopSpine';
import LinesExplorerContentPatternPathStopName from '@/components/LinesExplorerContentPatternPathStopName/LinesExplorerContentPatternPathStopName';
import { useLinesExplorerContext } from '@/contexts/LinesExplorerContext';

/* * */
Expand All @@ -28,55 +24,55 @@ export default function LinesExplorerContentPatternPathStop({ pathStopData }) {

const t = useTranslations('LinesExplorerContentPatternPathStop');
const linesExplorerContext = useLinesExplorerContext();
const [isThisStopSelected, setIsThisStopSelected] = useState(false);

//
// B. Handle actions
// B. Transform data

const isThisStopSelected = useMemo(() => {
return linesExplorerContext.entities.stop_id === pathStopData.stop.id;
}, [linesExplorerContext.entities.stop_id, pathStopData.stop.id]);

//
// C. Handle actions

const handleStopClick = () => {
setIsThisStopSelected((prev) => !prev);
linesExplorerContext.selectStop(pathStopData.stop.id);
};

//
// C. Render components
// D. Render components

return (
<div className={`${styles.container} ${isThisStopSelected && styles.selected}`} onClick={handleStopClick}>
<div className={styles.travelTime}></div>

{/* <LinePatternPathSpine style={pathStopData.stop_sequence === 0 ? 'start' : 'regular'} color={linesExplorerContext.entities.pattern.color} text_color={linesExplorerContext.entities.pattern.text_color} isSelected={isThisStopSelected} /> */}
<LinesExplorerContentPatternPathStopSpine style={pathStopData.stop_sequence === 0 ? 'start' : 'regular'} color={linesExplorerContext.entities.pattern.color} text_color={linesExplorerContext.entities.pattern.text_color} isSelected={isThisStopSelected} />

<div className={styles.info}>
<div className={styles.header}>
<div>{pathStopData.stop.id}</div>
<StopName id={pathStopData.stop.id} name={pathStopData.stop.name} tts_name={pathStopData.stop.tts_name} locality={pathStopData.stop.localiy} municipality={pathStopData.stop.municipality} />
{!isThisStopSelected && <StopRealTime pattern_code={linesExplorerContext.entities.pattern.id} stop_code={pathStopData.stop.id} />}
<div className={styles.ids}>
<CopyBadge label={`#${pathStopData.stop.id}`} value={pathStopData.stop.id} />
<CopyBadge label={`${pathStopData.stop.lat}, ${pathStopData.stop.lon}`} value={`${pathStopData.stop.lat} ${pathStopData.stop.lon}`} />
</div>
<LinesExplorerContentPatternPathStopName id={pathStopData.stop.id} name={pathStopData.stop.name} tts_name={pathStopData.stop.tts_name} locality={pathStopData.stop.localiy} municipality={pathStopData.stop.municipality} />
{!isThisStopSelected && <LinesExplorerContentPatternPathStopRealtime patternId={linesExplorerContext.entities.pattern.id} stopId={pathStopData.stop.id} />}
</div>

{isThisStopSelected && (
<div className={styles.body}>
<Text type="mini-label">Próximas circulações</Text>
<StopRealTime pattern_id={linesExplorerContext.entities.pattern.id} stop_id={pathStopData.stop.id} />
<LinesExplorerContentPatternPathStopRealtime patternId={linesExplorerContext.entities.pattern.id} stopId={pathStopData.stop.id} />
</div>
)}

{isThisStopSelected && (
<div className={styles.body}>
<Text type="mini-label">Horários previstos nesta paragem</Text>
<LinePatternPathTimetable index={pathStopData.stop_sequence} stopId={pathStopData.stop.id} />
<LinesExplorerContentPatternPathStopTimetable stopSequence={pathStopData.stop_sequence} stopId={pathStopData.stop.id} />
</div>
)}

{/* {isThisStopSelected && <StopPDF line_code={lineForm.values.line_code} stop_code={stop_code} direction={linesExplorerContext.entities.pattern.direction} />} */}
{/* {isThisStopSelected && (
<div className={styles.body}>
<div className={styles.ids}>
<CopyBadge label={`#${pathStopData.stop.id}`} value={pathStopData.stop.id} />
<CopyBadge label={`${pathStopData.stop.latitude}, ${pathStopData.stop.longitude}`} value={`${pathStopData.stop.latitude} ${pathStopData.stop.longitude}`} />
</div>
<LinePatternPathTimetable index={index} stop_code={stop_code} />
</div>
)} */}
{isThisStopSelected && <LinesExplorerContentPatternPathStopPdf lineId={linesExplorerContext.entities.line.id} stopId={pathStopData.stop.id} direction={linesExplorerContext.entities.pattern.direction} />}
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* * */

import styles from './LinesExplorerContentPatternPathStopName.module.css';
import Text from '@/components/Text/Text';
import AudioBadge from '@/components/AudioBadge/AudioBadge';

/* * */

export default function LinesExplorerContentPatternPathStopName({ id, name, tts_name, locality, municipality, selected = false, alignment = 'flex-start' }) {
//

// If none of the location strings are defined,
// then return an empty React fragment.
if (!locality && !municipality) {
return (
<div className={`${styles.container} ${styles[alignment]}`}>
<Text type={selected ? 'h2' : 'h3'} aria-label={tts_name || name}>
{name}
{/* {name} <AudioBadge type="stops" id={id} /> */}
</Text>
</div>
);
}

// If only locality is defined, then return it.
if (locality && !municipality) {
return (
<div className={`${styles.container} ${styles[alignment]}`}>
<Text type={selected ? 'h2' : 'h3'} aria-label={tts_name || name}>
{name}
{/* {name} <AudioBadge type="stops" id={id} /> */}
</Text>
<Text type="subtitle">{locality}</Text>
</div>
);
}

// If only municipality is defined, then return it.
if (!locality && municipality) {
return (
<div className={`${styles.container} ${styles[alignment]}`}>
<Text type={selected ? 'h2' : 'h3'} aria-label={tts_name || name}>
{name}
{/* {name} <AudioBadge type="stops" id={id} /> */}
</Text>
<Text type="subtitle">{municipality}</Text>
</div>
);
}

// If both locality and municipality are the same,
// return only one of them to avoid duplicate strings.
if (locality === municipality) {
return (
<div className={`${styles.container} ${styles[alignment]}`}>
<Text type={selected ? 'h2' : 'h3'} aria-label={tts_name || name}>
{name}
{/* {name} <AudioBadge type="stops" id={id} /> */}
</Text>
<Text type="subtitle">{locality}</Text>
</div>
);
}

// Return both if none of the previous conditions was matched.
return (
<div className={`${styles.container} ${styles[alignment]}`}>
<Text type={selected ? 'h2' : 'h3'} aria-label={tts_name || name}>
{name}
{/* {name} <AudioBadge type="stops" id={id} /> */}
</Text>
<Text type="subtitle">
{locality}, {municipality}
</Text>
</div>
);

//
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.container {
display: flex;
flex-direction: column;
gap: var(--size-xs);
}

.container.flex-start {
align-items: flex-start;
text-align: left;
}

.container.center {
align-items: center;
text-align: center;
}

.container.flex-end {
align-items: flex-end;
text-align: right;
}
Loading

0 comments on commit cdac3d1

Please sign in to comment.