refactor(web): split config hook/context (.ts) from provider (.tsx) to clear react-refresh lint
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,8 @@ import { expect, test, beforeEach } from "vitest";
|
|||||||
import { screen, waitFor, render } from "@testing-library/react";
|
import { screen, waitFor, render } from "@testing-library/react";
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
import i18n, { LOCALE_KEY } from "../i18n";
|
import i18n, { LOCALE_KEY } from "../i18n";
|
||||||
import { ConfigProvider, useConfig } from "./config-context";
|
import { ConfigProvider } from "./config-provider";
|
||||||
|
import { useConfig } from "./config-context";
|
||||||
|
|
||||||
function Probe() {
|
function Probe() {
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { createContext, useContext } from "react";
|
||||||
|
|
||||||
|
import type { components } from "../api/schema";
|
||||||
|
|
||||||
|
export type ConfigView = components["schemas"]["ConfigView"];
|
||||||
|
|
||||||
|
export const DEFAULTS: ConfigView = {
|
||||||
|
app_name: "Collection Management System",
|
||||||
|
default_language: "sv",
|
||||||
|
default_timezone: "Europe/Stockholm",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ConfigContext = createContext<ConfigView>(DEFAULTS);
|
||||||
|
|
||||||
|
export function useConfig(): ConfigView {
|
||||||
|
return useContext(ConfigContext);
|
||||||
|
}
|
||||||
@@ -1,23 +1,9 @@
|
|||||||
import { createContext, useContext, useEffect, type ReactNode } from "react";
|
import { useEffect, type ReactNode } from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
import type { components } from "../api/schema";
|
|
||||||
import { api } from "../api/client";
|
import { api } from "../api/client";
|
||||||
import i18n, { LOCALE_KEY } from "../i18n";
|
import i18n, { LOCALE_KEY } from "../i18n";
|
||||||
|
import { ConfigContext, DEFAULTS, type ConfigView } from "./config-context";
|
||||||
type ConfigView = components["schemas"]["ConfigView"];
|
|
||||||
|
|
||||||
const DEFAULTS: ConfigView = {
|
|
||||||
app_name: "Collection Management System",
|
|
||||||
default_language: "sv",
|
|
||||||
default_timezone: "Europe/Stockholm",
|
|
||||||
};
|
|
||||||
|
|
||||||
const ConfigContext = createContext<ConfigView>(DEFAULTS);
|
|
||||||
|
|
||||||
export function useConfig(): ConfigView {
|
|
||||||
return useContext(ConfigContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ConfigProvider({ children }: { children: ReactNode }) {
|
export function ConfigProvider({ children }: { children: ReactNode }) {
|
||||||
const { data } = useQuery({
|
const { data } = useQuery({
|
||||||
+1
-1
@@ -3,7 +3,7 @@ import { createRoot } from "react-dom/client";
|
|||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
|
||||||
import { App } from "./app";
|
import { App } from "./app";
|
||||||
import { ConfigProvider } from "./config/config-context";
|
import { ConfigProvider } from "./config/config-provider";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import "./i18n";
|
import "./i18n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user