mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-04 03:25:21 +00:00
PR clean up
This commit is contained in:
parent
95e5f23d25
commit
b37ce8ac33
12
frontend/src/components/tools/ToolLoadingFallback.tsx
Normal file
12
frontend/src/components/tools/ToolLoadingFallback.tsx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { Center, Stack, Loader, Text } from "@mantine/core";
|
||||||
|
|
||||||
|
export default function ToolLoadingFallback({ toolName }: { toolName?: string }) {
|
||||||
|
return (
|
||||||
|
<Center h="100%" w="100%">
|
||||||
|
<Stack align="center" gap="md">
|
||||||
|
<Loader size="lg" />
|
||||||
|
<Text c="dimmed" size="sm">
|
||||||
|
{toolName ? `Loading ${toolName}...` : "Loading tool..."}
|
||||||
|
</Text>
|
||||||
|
</Stack>
|
||||||
|
</Center>
|
@ -1,23 +1,12 @@
|
|||||||
import React, { Suspense } from "react";
|
import React, { Suspense } from "react";
|
||||||
import { Loader, Center, Stack, Text } from "@mantine/core";
|
|
||||||
import { useToolManagement } from "../../hooks/useToolManagement";
|
import { useToolManagement } from "../../hooks/useToolManagement";
|
||||||
import { BaseToolProps } from "../../types/tool";
|
import { BaseToolProps } from "../../types/tool";
|
||||||
|
import ToolLoadingFallback from "./ToolLoadingFallback";
|
||||||
|
|
||||||
interface ToolRendererProps extends BaseToolProps {
|
interface ToolRendererProps extends BaseToolProps {
|
||||||
selectedToolKey: string;
|
selectedToolKey: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loading fallback component for lazy-loaded tools
|
|
||||||
const ToolLoadingFallback = ({ toolName }: { toolName?: string }) => (
|
|
||||||
<Center h="100%" w="100%">
|
|
||||||
<Stack align="center" gap="md">
|
|
||||||
<Loader size="lg" />
|
|
||||||
<Text c="dimmed" size="sm">
|
|
||||||
{toolName ? `Loading ${toolName}...` : "Loading tool..."}
|
|
||||||
</Text>
|
|
||||||
</Stack>
|
|
||||||
</Center>
|
|
||||||
);
|
|
||||||
|
|
||||||
const ToolRenderer = ({
|
const ToolRenderer = ({
|
||||||
selectedToolKey,
|
selectedToolKey,
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import React, { createContext, useContext, useState, useCallback, ReactNode } from 'react';
|
import React, { createContext, useContext, useState, useCallback, ReactNode } from 'react';
|
||||||
import {
|
import {
|
||||||
MaxFiles,
|
MaxFiles,
|
||||||
FileSelectionState,
|
FileSelectionContextValue
|
||||||
FileSelectionActions,
|
|
||||||
FileSelectionComputed,
|
|
||||||
FileSelectionContextValue
|
|
||||||
} from '../types/tool';
|
} from '../types/tool';
|
||||||
|
|
||||||
interface FileSelectionProviderProps {
|
interface FileSelectionProviderProps {
|
||||||
@ -48,6 +45,10 @@ export function FileSelectionProvider({ children }: FileSelectionProviderProps)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access the file selection context.
|
||||||
|
* Throws if used outside a <FileSelectionProvider>.
|
||||||
|
*/
|
||||||
export function useFileSelection(): FileSelectionContextValue {
|
export function useFileSelection(): FileSelectionContextValue {
|
||||||
const context = useContext(FileSelectionContext);
|
const context = useContext(FileSelectionContext);
|
||||||
if (!context) {
|
if (!context) {
|
||||||
@ -56,21 +57,29 @@ export function useFileSelection(): FileSelectionContextValue {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns only the file selection values relevant for tools (e.g. merge, split, etc.)
|
||||||
|
// Use this in tool panels/components that need to know which files are selected and selection limits.
|
||||||
export function useToolFileSelection(): Pick<FileSelectionContextValue, 'selectedFiles' | 'maxFiles' | 'canSelectMore' | 'isAtLimit' | 'selectionCount'> {
|
export function useToolFileSelection(): Pick<FileSelectionContextValue, 'selectedFiles' | 'maxFiles' | 'canSelectMore' | 'isAtLimit' | 'selectionCount'> {
|
||||||
const { selectedFiles, maxFiles, canSelectMore, isAtLimit, selectionCount } = useFileSelection();
|
const { selectedFiles, maxFiles, canSelectMore, isAtLimit, selectionCount } = useFileSelection();
|
||||||
return { selectedFiles, maxFiles, canSelectMore, isAtLimit, selectionCount };
|
return { selectedFiles, maxFiles, canSelectMore, isAtLimit, selectionCount };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns actions for manipulating file selection state.
|
||||||
|
// Use this in components that need to update the selection, clear it, or change selection mode.
|
||||||
export function useFileSelectionActions(): Pick<FileSelectionContextValue, 'setSelectedFiles' | 'clearSelection' | 'setMaxFiles' | 'setIsToolMode'> {
|
export function useFileSelectionActions(): Pick<FileSelectionContextValue, 'setSelectedFiles' | 'clearSelection' | 'setMaxFiles' | 'setIsToolMode'> {
|
||||||
const { setSelectedFiles, clearSelection, setMaxFiles, setIsToolMode } = useFileSelection();
|
const { setSelectedFiles, clearSelection, setMaxFiles, setIsToolMode } = useFileSelection();
|
||||||
return { setSelectedFiles, clearSelection, setMaxFiles, setIsToolMode };
|
return { setSelectedFiles, clearSelection, setMaxFiles, setIsToolMode };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the raw file selection state (selected files, max files, tool mode).
|
||||||
|
// Use this for low-level state access, e.g. in context-aware UI.
|
||||||
export function useFileSelectionState(): Pick<FileSelectionContextValue, 'selectedFiles' | 'maxFiles' | 'isToolMode'> {
|
export function useFileSelectionState(): Pick<FileSelectionContextValue, 'selectedFiles' | 'maxFiles' | 'isToolMode'> {
|
||||||
const { selectedFiles, maxFiles, isToolMode } = useFileSelection();
|
const { selectedFiles, maxFiles, isToolMode } = useFileSelection();
|
||||||
return { selectedFiles, maxFiles, isToolMode };
|
return { selectedFiles, maxFiles, isToolMode };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns computed values derived from file selection state.
|
||||||
|
// Use this for file selection UI logic (e.g. disabling buttons when at limit).
|
||||||
export function useFileSelectionComputed(): Pick<FileSelectionContextValue, 'canSelectMore' | 'isAtLimit' | 'selectionCount' | 'isMultiFileMode'> {
|
export function useFileSelectionComputed(): Pick<FileSelectionContextValue, 'canSelectMore' | 'isAtLimit' | 'selectionCount' | 'isMultiFileMode'> {
|
||||||
const { canSelectMore, isAtLimit, selectionCount, isMultiFileMode } = useFileSelection();
|
const { canSelectMore, isAtLimit, selectionCount, isMultiFileMode } = useFileSelection();
|
||||||
return { canSelectMore, isAtLimit, selectionCount, isMultiFileMode };
|
return { canSelectMore, isAtLimit, selectionCount, isMultiFileMode };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user