Skip to content

Commit

Permalink
⚙️ Fix: Stops aparecendo corretamente e condicional para horário de f…
Browse files Browse the repository at this point in the history
…uncionamento (#105)
  • Loading branch information
Gabriel0109 committed Mar 4, 2024
1 parent 2897f50 commit 57c54ad
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 15 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"react-router-dom": "^6.4.5",
"react-toastify": "^9.1.1",
"sass": "^1.56.1",
"string-similarity": "^4.0.4",
"underscore": "^1.13.6"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions src/components/InfoCard/InfoCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function InfoCard() {
}
}, [plataforms])
function convertTime(timeString) {
const [hoursStr, minutesStr] = timeString.split(':');
const [hoursStr, minutesStr] = timeString?.split(':');
const hours = parseInt(hoursStr, 10);
const minutes = parseInt(minutesStr, 10);

Expand Down Expand Up @@ -173,9 +173,11 @@ export function InfoCard() {
</div>
<div className="flex flex-col ml-2.5">
<p className="text-sm">{e.trip_id?.trip_headsign ?? 'Circular'}</p>
{e.trip_id.route_id.route_type === 702 ?
<p className="text-xs">
Funcionamento: {format(convertTime(e.start_time), 'HH:mm')} - {format(convertTime(e.end_time), 'HH:mm')}
Funcionamento: {format(convertTime(e.start_time), 'HH:mm')} - {format(convertTime(e.end_time), 'HH:mm')}
</p>
: null}
</div>
</div>

Expand Down
3 changes: 1 addition & 2 deletions src/hooks/getMovingMarkers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ useEffect(() => {
}, []).sort((a, b) => a.start_time.localeCompare(b.start_time));

const currentTime = new Date().toLocaleString('en-US', { timeZone: 'America/Sao_Paulo', hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
const filteredObj = { ...obj1, closestStartTime: null, start_time: matched[0].start_time ?? null, end_time: matched[0].end_time ?? null };
const filteredObj = { ...obj1, closestStartTime: null, start_time: matched[0]?.start_time ?? null, end_time: matched[0]?.end_time ?? null };

if (combinedHeadways.length > 0) {

Expand Down Expand Up @@ -194,7 +194,6 @@ useEffect(() => {

return acc;
}, []);
console.log(filteredFrequenciesList)

setRoutesAndFrequencies(filteredFrequenciesList);
}
Expand Down
23 changes: 15 additions & 8 deletions src/hooks/getTrips.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createContext, useEffect, useState, useContext } from "react";
import { api } from "../services/api";
import { CodeContext } from "./getCode";
import { ServiceIdContext } from "./getServiceId";
import { findBestMatch } from "string-similarity";


export const TripContext = createContext()
Expand Down Expand Up @@ -56,23 +57,29 @@ export function TripProvider({ children }) {

useEffect(() => {
if (!isLoading) {
const sortedSequence = allSequenceStops.sort((a, b) => a.stop_sequence - b.stop_sequence )

const sortedSequence = allSequenceStops.sort((a, b) => a.stop_sequence - b.stop_sequence);

if (locationType === 1) {
const mapSequence = sortedSequence?.map(e => e.stop_id.stop_name).indexOf(name)
const mapSequenceIncludes = sortedSequence?.findIndex(e => e.stop_id.stop_name.includes(name))
if (mapSequence === -1) {
const filteredSequenceIncludes = sortedSequence?.splice(mapSequenceIncludes)
setSequenceInfo(filteredSequenceIncludes)
const stopNames = sortedSequence.map(e => e.stop_id.stop_name);
const matches = findBestMatch(name, stopNames);
const bestMatch = matches.bestMatch;

if (bestMatch.rating > 0.4) {
const index = stopNames.indexOf(bestMatch.target);
const filteredSequenceIncludes = sortedSequence.slice(index);
setSequenceInfo(filteredSequenceIncludes);
} else {
const filteredSequence = sortedSequence?.splice(mapSequence)
setSequenceInfo(filteredSequence)
const filteredSequenceIncludes = sortedSequence.slice(index)
setSequenceInfo(filteredSequenceIncludes)
}
} else {
const mapSequence = sortedSequence?.map(e => e.stop_id.stop_id).indexOf(stopId)
const filteredSequence = sortedSequence?.splice(mapSequence)
setSequenceInfo(filteredSequence)
}
}

}, [allSequenceStops])
return (
<TripContext.Provider value={{ trip, setTrip, tripSelector, sequenceInfo, stopInfo, setSequenceInfo, shape }}>
Expand Down
13 changes: 10 additions & 3 deletions src/pages/SearchMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,19 @@ export function SearchMain() {
<img className="inline-block mr-3" src={qrCode} alt="" />
Usar qrcode
</button>


<ul>

</ul>



</div>
<div className='text-white absolute bottom-0 z-1 right-0 left-0'>
<p className='text-center p-4'>
❤️ Feito em código aberto, acesse <a href="https://github.com/RJ-SMTR/mobilidade-rio-app" className='underline' target='blank'>aqui</a> e colabore!
</p>
</div>

{active ? <QrScanner
onDecode={(result) => window.location.href = result}
onError={(error) => console.log(error?.message)}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,11 @@ splaytree@^3.1.0:
resolved "https://registry.npmjs.org/splaytree/-/splaytree-3.1.1.tgz"
integrity sha512-9FaQ18FF0+sZc/ieEeXHt+Jw2eSpUgUtTLDYB/HXKWvhYVyOc7h1hzkn5MMO3GPib9MmXG1go8+OsBBzs/NMww==

string-similarity@^4.0.4:
version "4.0.4"
resolved "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz"
integrity sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ==

styled-components@^5.3.5, "styled-components@>= 2":
version "5.3.6"
resolved "https://registry.npmjs.org/styled-components/-/styled-components-5.3.6.tgz"
Expand Down

0 comments on commit 57c54ad

Please sign in to comment.