mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 13:35:42 +09:00
refactor(schema): simplify validation and OpenAPI generation (#2709)
This commit is contained in:
1 parent
4bc5593f9f
commit
de1fd95a99
510 files changed
+29494
-36131
No files matched your search
@@ -99,7 +99,7 @@ const RootComponent = React.forwardRef<HTMLDivElement, ModalProps>(
|
||||
if (typeof ref === 'function') {
|
||||
ref(node);
|
||||
} else if (ref) {
|
||||
(ref as React.MutableRefObject<HTMLDivElement | null>).current = node;
|
||||
ref.current = node;
|
||||
}
|
||||
},
|
||||
[ref],
|
||||
|
||||
@@ -129,7 +129,7 @@ export const SettingsModalDesktopScroll: React.FC<SettingsModalDesktopScrollProp
|
||||
if (typeof scrollerRef === 'function') {
|
||||
scrollerRef(node);
|
||||
} else {
|
||||
(scrollerRef as React.MutableRefObject<HTMLElement | null>).current = node;
|
||||
scrollerRef.current = node;
|
||||
}
|
||||
});
|
||||
return (
|
||||
|
||||
@@ -423,11 +423,11 @@ function resolvePinnedCallChannel(directMessagesDisabled: boolean): Channel | nu
|
||||
|
||||
interface DMChannelVisibilityControllerState {
|
||||
readonly removalDelayMs: number;
|
||||
readonly removalTimers: React.MutableRefObject<Map<string, number>>;
|
||||
readonly removalTimers: React.RefObject<Map<string, number>>;
|
||||
readonly orderedUnreadChannels: ReadonlyArray<Channel>;
|
||||
readonly setVisibleChannels: React.Dispatch<React.SetStateAction<ReadonlyArray<Channel>>>;
|
||||
readonly unreadChannels: ReadonlyArray<Channel>;
|
||||
readonly unreadIdsRef: React.MutableRefObject<ReadonlySet<string>>;
|
||||
readonly unreadIdsRef: React.RefObject<ReadonlySet<string>>;
|
||||
}
|
||||
|
||||
interface ProjectVisibleDMChannelsRequest {
|
||||
@@ -437,11 +437,11 @@ interface ProjectVisibleDMChannelsRequest {
|
||||
|
||||
class DMChannelVisibilityController {
|
||||
private readonly removalDelayMs: number;
|
||||
private readonly removalTimers: React.MutableRefObject<Map<string, number>>;
|
||||
private readonly removalTimers: React.RefObject<Map<string, number>>;
|
||||
private readonly orderedUnreadChannels: ReadonlyArray<Channel>;
|
||||
private readonly setVisibleChannels: React.Dispatch<React.SetStateAction<ReadonlyArray<Channel>>>;
|
||||
private readonly unreadChannels: ReadonlyArray<Channel>;
|
||||
private readonly unreadIdsRef: React.MutableRefObject<ReadonlySet<string>>;
|
||||
private readonly unreadIdsRef: React.RefObject<ReadonlySet<string>>;
|
||||
|
||||
public constructor({
|
||||
removalDelayMs,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
|
||||
export type ScrollIndicatorSeverity = 'mention' | 'unread';
|
||||
export type ScrollIndicatorDirection = 'top' | 'bottom';
|
||||
@@ -238,7 +238,7 @@ export type ScrollIndicatorMachineSnapshot = SnapshotFrom<typeof scrollIndicator
|
||||
export type ScrollIndicatorStateValue = 'hidden' | 'visible';
|
||||
|
||||
export function createScrollIndicatorSnapshot(input: ScrollIndicatorMachineInput = {}): ScrollIndicatorMachineSnapshot {
|
||||
return getInitialSnapshot(scrollIndicatorStateMachine, input);
|
||||
return initialTransition(scrollIndicatorStateMachine, input)[0];
|
||||
}
|
||||
|
||||
export function transitionScrollIndicatorSnapshot(
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import {type DragItem, DragItemType, type DropResult} from '@app/features/app/components/layout/types/DndTypes';
|
||||
import {getVerticalDropTargetHeight, resolveVerticalDropEdge} from '@app/features/ui/dnd/DropGeometry';
|
||||
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
|
||||
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
|
||||
export interface ChannelReorderPoint {
|
||||
x: number;
|
||||
@@ -244,7 +244,7 @@ export type ChannelReorderSnapshot = SnapshotFrom<typeof channelReorderStateMach
|
||||
export type ChannelReorderStateValue = 'idle' | 'resolving' | 'targeting' | 'voiceParticipantTransfer' | 'blocked';
|
||||
|
||||
export function createChannelReorderSnapshot(): ChannelReorderSnapshot {
|
||||
return getInitialSnapshot(channelReorderStateMachine);
|
||||
return initialTransition(channelReorderStateMachine)[0];
|
||||
}
|
||||
|
||||
export function transitionChannelReorderSnapshot(
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
import {RelativePosition} from '@app/features/ui/RelativePosition';
|
||||
import {
|
||||
assign,
|
||||
getInitialSnapshot,
|
||||
initialTransition,
|
||||
type MachineSnapshot,
|
||||
type MetaObject,
|
||||
type NonReducibleUnknown,
|
||||
@@ -380,7 +380,7 @@ export type GuildReorderSnapshot = MachineSnapshot<
|
||||
>;
|
||||
|
||||
export function createGuildReorderSnapshot(): GuildReorderSnapshot {
|
||||
return getInitialSnapshot(guildReorderStateMachine);
|
||||
return initialTransition(guildReorderStateMachine)[0];
|
||||
}
|
||||
|
||||
export function transitionGuildReorderSnapshot({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {MessageNotifications} from '@fluxer/constants/src/NotificationConstants';
|
||||
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
import type {ChannelUnreadState, ChannelUnreadStateInput} from './ChannelUnreadState';
|
||||
|
||||
interface ChannelUnreadMachineContext extends ChannelUnreadStateInput {}
|
||||
@@ -74,7 +74,7 @@ export const channelUnreadStateMachine = setup({
|
||||
export type ChannelUnreadSnapshot = SnapshotFrom<typeof channelUnreadStateMachine>;
|
||||
|
||||
export function createChannelUnreadSnapshot(input: ChannelUnreadStateInput): ChannelUnreadSnapshot {
|
||||
return getInitialSnapshot(channelUnreadStateMachine, input);
|
||||
return initialTransition(channelUnreadStateMachine, input)[0];
|
||||
}
|
||||
|
||||
export function transitionChannelUnreadSnapshot(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
|
||||
export type WizardStep =
|
||||
| 'welcome'
|
||||
@@ -157,7 +157,7 @@ export const setupWizardStateMachine = setup({
|
||||
export type SetupWizardSnapshot = SnapshotFrom<typeof setupWizardStateMachine>;
|
||||
|
||||
export function createSetupWizardSnapshot(): SetupWizardSnapshot {
|
||||
return getInitialSnapshot(setupWizardStateMachine);
|
||||
return initialTransition(setupWizardStateMachine)[0];
|
||||
}
|
||||
|
||||
export function transitionSetupWizardSnapshot(
|
||||
|
||||
@@ -127,8 +127,7 @@ export const FriendSelector: React.FC<FriendSelectorProps> = observer(
|
||||
const isMaxed = maxSelections !== undefined && selectedUserIds.length >= maxSelections;
|
||||
const isMutableRefObject = (
|
||||
ref: React.Ref<HTMLInputElement> | undefined,
|
||||
): ref is React.MutableRefObject<HTMLInputElement | null> =>
|
||||
typeof ref === 'object' && ref !== null && 'current' in ref;
|
||||
): ref is React.RefObject<HTMLInputElement | null> => typeof ref === 'object' && ref !== null && 'current' in ref;
|
||||
const renderSearchInput = ({inputProps, inputClassName, ref: forwardedRef}: RenderInputArgs) => {
|
||||
const handleRef = (node: HTMLInputElement | null) => {
|
||||
inputRef.current = node;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
import {initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
|
||||
|
||||
export type HoverStateValue = 'idle' | 'hovering';
|
||||
|
||||
@@ -32,7 +32,7 @@ export const hoverStateMachine = setup({
|
||||
export type HoverStateSnapshot = SnapshotFrom<typeof hoverStateMachine>;
|
||||
|
||||
export function createHoverStateSnapshot(): HoverStateSnapshot {
|
||||
return getInitialSnapshot(hoverStateMachine);
|
||||
return initialTransition(hoverStateMachine)[0];
|
||||
}
|
||||
|
||||
export function transitionHoverStateSnapshot(snapshot: HoverStateSnapshot, event: HoverStateEvent): HoverStateSnapshot {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import type {FormEvent} from 'react';
|
||||
import type {SubmitEvent} from 'react';
|
||||
import {useCallback, useLayoutEffect, useState} from 'react';
|
||||
|
||||
interface FormField {
|
||||
@@ -33,7 +33,7 @@ export interface UseFormReturn {
|
||||
setErrors: (errors: ReadonlyMap<string, string>) => void;
|
||||
getValue: (fieldName: string) => string;
|
||||
getError: (fieldName: string) => string | undefined;
|
||||
handleSubmit: (event?: FormEvent) => Promise<void>;
|
||||
handleSubmit: (event?: SubmitEvent<HTMLFormElement>) => Promise<void>;
|
||||
isSubmitting: boolean;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ export function useForm({initialValues, onSubmit}: UseFormOptions): UseFormRetur
|
||||
const getValue = useCallback((fieldName: string): string => fields.get(fieldName)?.value ?? '', [fields]);
|
||||
const getError = useCallback((fieldName: string): string | undefined => fields.get(fieldName)?.error, [fields]);
|
||||
const handleSubmit = useCallback(
|
||||
async (event?: FormEvent) => {
|
||||
async (event?: SubmitEvent<HTMLFormElement>) => {
|
||||
event?.preventDefault();
|
||||
if (lifecycle.activeSubmission != null) {
|
||||
return;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {type LegacyRef, type MutableRefObject, type RefCallback, useCallback, useRef} from 'react';
|
||||
import {type Ref, type RefCallback, useCallback, useRef} from 'react';
|
||||
|
||||
export function useMergeRefs<T>(
|
||||
refs: Array<MutableRefObject<T | null> | LegacyRef<T> | undefined | null>,
|
||||
): RefCallback<T> {
|
||||
export function useMergeRefs<T>(refs: Array<Ref<T> | undefined>): RefCallback<T> {
|
||||
const latestRefs = useRef(refs);
|
||||
latestRefs.current = refs;
|
||||
return useCallback((value: T | null) => {
|
||||
@@ -12,7 +10,7 @@ export function useMergeRefs<T>(
|
||||
if (typeof ref === 'function') {
|
||||
ref(value);
|
||||
} else if (ref != null) {
|
||||
(ref as MutableRefObject<T | null>).current = value;
|
||||
ref.current = value;
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
Reference in new issue
Block a user