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

Convert icon functionality from filename to number #108

Merged
merged 7 commits into from
Sep 4, 2023

Conversation

liamboddin
Copy link
Contributor

…string for the database type

@liamboddin liamboddin linked an issue Aug 30, 2023 that may be closed by this pull request
@liamboddin liamboddin changed the title Converted icon to new functionality as a number for the API type but … Convert icon functionality from filename to number Aug 30, 2023
Server/src/models/api.ts Outdated Show resolved Hide resolved
@n1kPLV n1kPLV marked this pull request as ready for review September 1, 2023 19:31
@n1kPLV
Copy link
Contributor

n1kPLV commented Sep 1, 2023

Review-Hint: The Website/public directory contains static files, mostly icons.

Copy link
Contributor

@n1kPLV n1kPLV left a comment

Choose a reason for hiding this comment

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

Looks good to me. However, some of these changes are my own, so I would like someone else to review this too

@@ -32,9 +32,20 @@ export type FullTrack = BareTrack & {

export type TrackList = BareTrack[];

export const POITypeIconValues = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I used this instead of an enum for the website code, as the "backwards mapping" automatically added by TypeScript would have forced me to write messier code. This is functionally equivalent in most ways to an enum, when combined with the type definition below.

};

export const POIIconImg: Readonly<Record<POITypeIcon, string>> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am still not quite sure if this file is the correct place for this definition, but I had to fit it somewhere...

Copy link
Contributor

Choose a reason for hiding this comment

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

As I have touched this file, it got reformatted to match the prettier rules defined for the website.

@@ -186,14 +186,32 @@ export default function POIManagement({ poiTypes, tracks }: { poiTypes: POIType[
name={"selPoi"}
className="col-span-5 border border-gray-500 dark:bg-slate-700 rounded"
options={poiOptions}
unstyled={true}
Copy link
Contributor

Choose a reason for hiding this comment

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

To add "dark mode" support, it was easier to remove the default style from react-select and define my own style. This should look essentially the same in "light mode", and actually usable in "dark mode".

If this works, I will bring this style to the other react-select components too, possibly by extracting the style into a separate component

const enriched_poi_types: (POIType & { leaf_icon: L.Icon })[] = useMemo(
() =>
poi_types.map(pt => {
const icon_src = POIIconImg[pt.icon] ?? POIIconImg[POITypeIconValues.Generic];
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic for creating the marker icon is now a little bit more complex than before. If the icon value is not one of the known ones, we will just use the "Generic" icon.

{ path: "/poiTypeIcons/lesser_level_crossing.svg", name: "Unbeschilderter Bahnübergang" },
{ path: "/poiTypeIcons/parking.svg", name: "Haltepunkt" }
];
const POI_ICONS: POITypeIcon[] = Object.values(POITypeIconValues);
Copy link
Contributor

Choose a reason for hiding this comment

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

This would have been much more messy, and much less type-safe with a typescript enum.

<th className={"mx-2 border-b-black border-b px-2"}>Batterieladung</th>
<th className={"mx-2 border-b-black border-b px-2"}>Auf Karte anzeigen</th>
<th className={"mx-2 border-b-black dark:border-b-white border-b px-2"}>Name</th>
<th className={"mx-2 border-b-black dark:border-b-white hidden sm:table-cell border-b px-2"}>geog. Breite</th>
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimization for mobile devices: Coordinates are hidden on small screens.

@@ -71,6 +71,7 @@ export default class POIController {
},
data: {
name: name,
icon: icon,
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope this doesn't collide too much with any changes made in #112

continue
}
// Check if the icon number is a member of the enum.
if (!(poiIcon in POITypeIcon)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As an enum is compiled down to an object, this should check -- using the backwards mapping -- if the number is a value assigned to an enum member.

@liamboddin
Copy link
Contributor Author

liamboddin commented Sep 3, 2023

It would be possible to remove some of the data sent over the API. I think it might be possible to remove the isTurningPoint-flag, change up the typeId in the POIs to something like icon. Right now the icon needs to be loaded with an extra request to POIType.

At this point I am not sure, if it would be clever to do that though, as this project is coming towards its end. The current version on this definitely runnable and works out fine. These changes would not change much in the performance as the POIs are rather considered static i.e. they are not requested very frequently

@n1kPLV what do you think about further API changes?

@liamboddin liamboddin linked an issue Sep 3, 2023 that may be closed by this pull request
@liamboddin
Copy link
Contributor Author

liamboddin commented Sep 4, 2023

Although this would affect the App-API as well with the current API-Types... This change will not be a priority as of right now.

@n1kPLV
Copy link
Contributor

n1kPLV commented Sep 4, 2023

I have already removed the option to set the isTurningPoint flag, always setting it to false. I too think that it is redundant, and I hope nothing relys on that flag being used correctly.

@liamboddin liamboddin merged commit eea9be3 into development Sep 4, 2023
2 checks passed
@liamboddin liamboddin deleted the 107-poi-icon branch September 4, 2023 09:52
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.

Change usage of icon in DB-POIType Turning point POI type
2 participants