mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
Use useTransition for faster UI
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect, useTransition } from "react";
|
||||||
|
|
||||||
import { useSetAtom } from "jotai";
|
import { useSetAtom } from "jotai";
|
||||||
import L from "leaflet";
|
import L from "leaflet";
|
||||||
@@ -8,6 +8,7 @@ import { mapBoundsAtom } from "@/app/atoms";
|
|||||||
|
|
||||||
const MapEvents = () => {
|
const MapEvents = () => {
|
||||||
const setMapBounds = useSetAtom(mapBoundsAtom);
|
const setMapBounds = useSetAtom(mapBoundsAtom);
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
|
||||||
const worldBounds = L.latLngBounds(L.latLng(-90, -180), L.latLng(90, 180));
|
const worldBounds = L.latLngBounds(L.latLng(-90, -180), L.latLng(90, 180));
|
||||||
const franceBounds = L.latLngBounds(
|
const franceBounds = L.latLngBounds(
|
||||||
@@ -17,10 +18,12 @@ const MapEvents = () => {
|
|||||||
|
|
||||||
const map = useMapEvent("moveend", () => {
|
const map = useMapEvent("moveend", () => {
|
||||||
// Set the map bounds atoms when the user pans/zooms
|
// Set the map bounds atoms when the user pans/zooms
|
||||||
|
startTransition(() => {
|
||||||
setMapBounds(map.getBounds());
|
setMapBounds(map.getBounds());
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// viewport agnostic centering of France & max world bounds
|
// Viewport agnostic centering of France & max world bounds
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
map.setView(franceBounds.getCenter(), map.getBoundsZoom(franceBounds));
|
map.setView(franceBounds.getCenter(), map.getBoundsZoom(franceBounds));
|
||||||
map.setMaxBounds(worldBounds);
|
map.setMaxBounds(worldBounds);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { useTransition } from "react";
|
||||||
|
|
||||||
import { useAtom } from "jotai/index";
|
import { useAtom } from "jotai/index";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { IoCloseOutline } from "react-icons/io5";
|
import { IoCloseOutline } from "react-icons/io5";
|
||||||
@@ -7,6 +9,13 @@ import { searchStringAtom } from "@/app/atoms";
|
|||||||
const SearchBar = () => {
|
const SearchBar = () => {
|
||||||
const t = useTranslations("Tournaments");
|
const t = useTranslations("Tournaments");
|
||||||
const [searchString, setSearchString] = useAtom(searchStringAtom);
|
const [searchString, setSearchString] = useAtom(searchStringAtom);
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
|
||||||
|
const updateSearchString = (str: string) => {
|
||||||
|
startTransition(() => {
|
||||||
|
setSearchString(str);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-white dark:bg-gray-800">
|
<div className="bg-white dark:bg-gray-800">
|
||||||
@@ -43,7 +52,7 @@ const SearchBar = () => {
|
|||||||
className="block rounded-lg border border-gray-300 bg-gray-50 p-2.5 px-10 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
|
className="block rounded-lg border border-gray-300 bg-gray-50 p-2.5 px-10 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
|
||||||
placeholder={t("searchPlaceholder")}
|
placeholder={t("searchPlaceholder")}
|
||||||
value={searchString}
|
value={searchString}
|
||||||
onChange={(e) => setSearchString(e.target.value)}
|
onChange={(e) => updateSearchString(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user