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

added the api for trip details, created the tripdetailpane with all information #28

Merged
merged 7 commits into from
Aug 1, 2024

Conversation

aaronbrethorst
Copy link
Member

@aaronbrethorst aaronbrethorst commented Jul 25, 2024

image

…e current location of bus (30 sec interval update), enhanced the modal pane UI, and user icon
@tarunsinghofficial tarunsinghofficial marked this pull request as ready for review July 29, 2024 15:22
@aaronbrethorst aaronbrethorst self-assigned this Jul 30, 2024
Copy link
Member Author

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking really good! I have noted a number of things I'd like to see changed before merging, but I love how effective you've been in tackling this task!

/>
{/each}
</div>
</div>
</div>
{/if}

{#if showTripDetails}
<div class="trip-details-modal scrollbar-hidden">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract this into a new component. TripDetailsModal, maybe?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Done.

/>
{/if}
{#if index === currentStopIndex}
<FontAwesomeIcon
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing this work on any of the stops I'm testing out. Can you double check it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the issue now.


onMount(() => {
loadTripDetails();
interval = setInterval(loadTripDetails, 30000);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

url += `&serviceDate=${serviceDate}`;
}
const response = await fetch(url);
if (response.ok) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try flipping these conditions around and using an early return in order to decrease the level of control flow nesting. i.e.:

if (!response.ok) {
    error = 'Unable to fetch trip details';
    return;
}

less nesting improves readability and understanding for anyone who reads this code after you :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with the recommended changes.

const response = await fetch(url);
if (response.ok) {
const data = await response.json();
tripDetails = data.data.entry;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest extracting data.data into its own local variable and using that in place of data.data throughout this code:

const jsonBody = await response.json();
const data = jsonBody.data;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted the data into the local variable.

const data = await response.json();
tripDetails = data.data.entry;

if (data.data.references && data.data.references.routes) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that you have data extracted above, you can use that along with optional chaining to simplify these conditions:

if (data?.references?.routes) {
  // ...
}

routeInfo = data.data.references.routes.find((route) => route.id === tripDetails.routeId);
}

if (data.data.references && data.data.references.stops) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

}, {});
}

if (tripDetails.status && tripDetails.status.closestStop) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this becomes if (tripDetails.status?.closestStop)


calculateBusPosition();

console.log('Trip details:', tripDetails);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these still necessary? if not, please delete them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No! Deleted all logs.

@tarunsinghofficial
Copy link
Collaborator

Hi @aaronbrethorst,

This PR is now ready to be merged. The issue of not showing the user location is fixed now. Working fine.

@tarunsinghofficial tarunsinghofficial self-requested a review August 1, 2024 14:04
Copy link
Member Author

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work @tarunsinghofficial. I made a few more tweaks and am merging. thanks for your hard work on this!

* Replace the location dot with an icon of a person walking
* Move it into the bottom right corner of the trip icon box so that both the bus icon and person icons can be seen at once
@aaronbrethorst aaronbrethorst merged commit a51553d into main Aug 1, 2024
3 checks passed
@aaronbrethorst aaronbrethorst deleted the trip-details branch August 1, 2024 21:48
@tarunsinghofficial
Copy link
Collaborator

nice work @tarunsinghofficial. I made a few more tweaks and am merging. thanks for your hard work on this!

Nice UI enhancement on Tripdetailspane. Thanks for the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants