Skip to content

Commit

Permalink
various optimizations & fixes
Browse files Browse the repository at this point in the history
 - memoize useRouteTitle()
 - fix type of default 404 template name
 - fix Geo & Draw state issues
  • Loading branch information
sheppard committed Oct 4, 2023
1 parent f3e823d commit 441caab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
3 changes: 1 addition & 2 deletions packages/map-gl-web/src/overlays/Draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ export default function Draw({ type, required, data, setData }) {
controls.trash = true;
}
const draw = useControl(
(props) => {
() => {
const { classes } = MapboxDraw.constants;
for (const [key, value] of Object.entries(classes)) {
if (value.startsWith("mapboxgl-")) {
classes[key] = value.replace("mapboxgl-", "maplibregl-");
}
}
return new MapboxDraw({
...props,
displayControlsDefault: false,
controls,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/map/src/inputs/Geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import PropTypes from "prop-types";
export default function Geo({
name,
type,
mapId = null,
mapId = undefined,
required,
label,
hint,
Expand Down
25 changes: 14 additions & 11 deletions packages/react/src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,20 @@ export function useRouteTitle(routeName) {
{ getRouteTitle } = app.router,
config = useConfig();

function routeTitle(routeName) {
const [name, mode, variant] = app.splitRoute(routeName);
const page_config = config.pages[name] || {
name,
};
return getRouteTitle({
page_config,
mode,
variant,
});
}
const routeTitle = useCallback(
(routeName) => {
const [name, mode, variant] = app.splitRoute(routeName);
const page_config = config.pages[name] || {
name,
};
return getRouteTitle({
page_config,
mode,
variant,
});
},
[app, routeName, config]
);

if (routeName) {
return routeTitle(routeName);
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const defaultQuerySerializer = {
var router = {
config: {
store: "main",
tmpl404: 404,
tmpl404: "404",
debug: false,
getTemplateName: (name) => name,
querySerializer: defaultQuerySerializer,
Expand Down

0 comments on commit 441caab

Please sign in to comment.