mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 04:50:36 +03:00
R: useContext -> use hook
This commit is contained in:
parent
cad521f46d
commit
ef79f3b83e
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { createContext, useContext, useEffect, useState } from 'react';
|
import { createContext, use, useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
|
|
||||||
export interface NavigationProps {
|
export interface NavigationProps {
|
||||||
|
@ -23,9 +23,9 @@ interface INavigationContext {
|
||||||
setIsBlocked: (value: boolean) => void;
|
setIsBlocked: (value: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NavigationContext = createContext<INavigationContext | null>(null);
|
export const NavigationContext = createContext<INavigationContext | null>(null);
|
||||||
export const useConceptNavigation = () => {
|
export const useConceptNavigation = () => {
|
||||||
const context = useContext(NavigationContext);
|
const context = use(NavigationContext);
|
||||||
if (!context) {
|
if (!context) {
|
||||||
throw new Error('useConceptNavigation has to be used within <NavigationState>');
|
throw new Error('useConceptNavigation has to be used within <NavigationState>');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { createContext, useContext, useEffect, useState } from 'react';
|
import { createContext, use, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { urls, useConceptNavigation } from '@/app';
|
import { urls, useConceptNavigation } from '@/app';
|
||||||
import { useAuthSuspense } from '@/features/auth';
|
import { useAuthSuspense } from '@/features/auth';
|
||||||
|
@ -44,9 +44,9 @@ export interface IOssEditContext {
|
||||||
setSelected: React.Dispatch<React.SetStateAction<number[]>>;
|
setSelected: React.Dispatch<React.SetStateAction<number[]>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const OssEditContext = createContext<IOssEditContext | null>(null);
|
export const OssEditContext = createContext<IOssEditContext | null>(null);
|
||||||
export const useOssEdit = () => {
|
export const useOssEdit = () => {
|
||||||
const context = useContext(OssEditContext);
|
const context = use(OssEditContext);
|
||||||
if (context === null) {
|
if (context === null) {
|
||||||
throw new Error('useOssEdit has to be used within <OssEditState>');
|
throw new Error('useOssEdit has to be used within <OssEditState>');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { createContext, useContext, useState } from 'react';
|
import { createContext, use, useState } from 'react';
|
||||||
import { useFormContext } from 'react-hook-form';
|
import { useFormContext } from 'react-hook-form';
|
||||||
|
|
||||||
import { useDialogsStore } from '@/stores/dialogs';
|
import { useDialogsStore } from '@/stores/dialogs';
|
||||||
|
@ -25,9 +25,9 @@ export interface ITemplateContext {
|
||||||
onChangeFilterCategory: (newFilterCategory: IConstituenta | null) => void;
|
onChangeFilterCategory: (newFilterCategory: IConstituenta | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TemplateContext = createContext<ITemplateContext | null>(null);
|
export const TemplateContext = createContext<ITemplateContext | null>(null);
|
||||||
export const useTemplateContext = () => {
|
export const useTemplateContext = () => {
|
||||||
const context = useContext(TemplateContext);
|
const context = use(TemplateContext);
|
||||||
if (context === null) {
|
if (context === null) {
|
||||||
throw new Error('useTemplateContext has to be used within <TemplateState>');
|
throw new Error('useTemplateContext has to be used within <TemplateState>');
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ interface EditorControlsProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EditorControls({ constituenta, disabled, onEditTerm }: EditorControlsProps) {
|
export function EditorControls({ constituenta, disabled, onEditTerm }: EditorControlsProps) {
|
||||||
const { schema } = useRSEdit();
|
const schema = useRSEdit().schema;
|
||||||
const { isModified } = useModificationStore();
|
const { isModified } = useModificationStore();
|
||||||
const isProcessing = useMutatingRSForm();
|
const isProcessing = useMutatingRSForm();
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ export function EditorRSExpression({
|
||||||
onShowTypeGraph,
|
onShowTypeGraph,
|
||||||
...restProps
|
...restProps
|
||||||
}: EditorRSExpressionProps) {
|
}: EditorRSExpressionProps) {
|
||||||
const { schema } = useRSEdit();
|
const schema = useRSEdit().schema;
|
||||||
|
|
||||||
const [isModified, setIsModified] = useState(false);
|
const [isModified, setIsModified] = useState(false);
|
||||||
const rsInput = useRef<ReactCodeMirrorRef>(null);
|
const rsInput = useRef<ReactCodeMirrorRef>(null);
|
||||||
|
|
|
@ -8,8 +8,8 @@ import { colorBgSchemas } from '../../../colors';
|
||||||
import { useRSEdit } from '../RSEditContext';
|
import { useRSEdit } from '../RSEditContext';
|
||||||
|
|
||||||
export function SchemasGuide() {
|
export function SchemasGuide() {
|
||||||
const { items: libraryItems } = useLibrary();
|
const libraryItems = useLibrary().items;
|
||||||
const { schema } = useRSEdit();
|
const schema = useRSEdit().schema;
|
||||||
|
|
||||||
const schemas = (() => {
|
const schemas = (() => {
|
||||||
const processed = new Set<number>();
|
const processed = new Set<number>();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { createContext, useContext, useEffect, useState } from 'react';
|
import { createContext, use, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { urls, useConceptNavigation } from '@/app';
|
import { urls, useConceptNavigation } from '@/app';
|
||||||
import { useAuthSuspense } from '@/features/auth';
|
import { useAuthSuspense } from '@/features/auth';
|
||||||
|
@ -66,9 +66,9 @@ export interface IRSEditContext {
|
||||||
promptTemplate: () => void;
|
promptTemplate: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RSEditContext = createContext<IRSEditContext | null>(null);
|
export const RSEditContext = createContext<IRSEditContext | null>(null);
|
||||||
export const useRSEdit = () => {
|
export const useRSEdit = () => {
|
||||||
const context = useContext(RSEditContext);
|
const context = use(RSEditContext);
|
||||||
if (context === null) {
|
if (context === null) {
|
||||||
throw new Error('useRSEdit has to be used within <RSEditState>');
|
throw new Error('useRSEdit has to be used within <RSEditState>');
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ export function ConstituentsSearch({ dense }: ConstituentsSearchProps) {
|
||||||
const setSource = useCstSearchStore(state => state.setSource);
|
const setSource = useCstSearchStore(state => state.setSource);
|
||||||
const toggleInherited = useCstSearchStore(state => state.toggleInherited);
|
const toggleInherited = useCstSearchStore(state => state.toggleInherited);
|
||||||
|
|
||||||
const { schema } = useRSEdit();
|
const schema = useRSEdit().schema;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex border-b clr-input rounded-t-md'>
|
<div className='flex border-b clr-input rounded-t-md'>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user