-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
…string for the database type
Review-Hint: The |
There was a problem hiding this 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 = { |
There was a problem hiding this comment.
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>> = { |
There was a problem hiding this comment.
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...
Website/src/utils/rotatingIcon.ts
Outdated
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
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 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? |
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. |
I have already removed the option to set the |
…string for the database type