Quellcode des ICON CRM (6)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import React, { createContext, useContext } from 'react';
|
||||
import type { View } from '../types';
|
||||
|
||||
/*
|
||||
* Ansichtswechsel fuer tief liegende Komponenten.
|
||||
*
|
||||
* Eine angeklickte @-Erwaehnung oder ein Treffer der globalen Suche muss die
|
||||
* passende Karte oeffnen koennen, ohne dass jede Ebene dazwischen einen
|
||||
* Rueckruf durchreicht.
|
||||
*/
|
||||
|
||||
export type OpenTarget = 'contact' | 'company' | 'tender' | 'project' | 'lead' | 'user';
|
||||
|
||||
/** Reiter der Einstellungen - auch von aussen ansteuerbar. */
|
||||
export type SettingsTab = 'konto' | 'benutzer' | 'stammdaten' | 'ki' | 'diktat';
|
||||
|
||||
interface NavigationValue {
|
||||
setView: (view: View) => void;
|
||||
/** Oeffnet die Karte eines Datensatzes - wechselt dabei die Ansicht. */
|
||||
open: (type: OpenTarget, id: number) => void;
|
||||
/**
|
||||
* Wechselt in die Einstellungen und oeffnet dort einen bestimmten Reiter.
|
||||
*
|
||||
* Gebraucht fuer das Diktat: der Knopf im Formular meldet, dass das
|
||||
* Sprachmodell fehlt, und muss direkt dorthin fuehren koennen, wo es geladen
|
||||
* wird - ein blosser Hinweis "steht in den Einstellungen" waere eine
|
||||
* Suchaufgabe.
|
||||
*/
|
||||
goToSettings: (tab: SettingsTab) => void;
|
||||
}
|
||||
|
||||
const NavigationContext = createContext<NavigationValue | null>(null);
|
||||
|
||||
export const NavigationProvider: React.FC<{ value: NavigationValue; children: React.ReactNode }> = ({
|
||||
value,
|
||||
children,
|
||||
}) => <NavigationContext.Provider value={value}>{children}</NavigationContext.Provider>;
|
||||
|
||||
export function useNavigation(): NavigationValue {
|
||||
const ctx = useContext(NavigationContext);
|
||||
if (!ctx) throw new Error('useNavigation muss innerhalb von <NavigationProvider> verwendet werden.');
|
||||
return ctx;
|
||||
}
|
||||
Reference in New Issue
Block a user