mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
feat(core): add split view to experimental features settings (#6093)
This commit is contained in:
24
packages/frontend/core/src/hooks/affine/use-user-features.ts
Normal file
24
packages/frontend/core/src/hooks/affine/use-user-features.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { FeatureType, getUserFeaturesQuery } from '@affine/graphql';
|
||||
import type { BareFetcher, Middleware } from 'swr';
|
||||
|
||||
import { useQueryImmutable } from '../use-query';
|
||||
|
||||
const wrappedFetcher = (fetcher: BareFetcher<any> | null, ...args: any[]) =>
|
||||
fetcher?.(...args).catch(() => null);
|
||||
|
||||
const errorHandler: Middleware = useSWRNext => (key, fetcher, config) => {
|
||||
return useSWRNext(key, wrappedFetcher.bind(null, fetcher), config);
|
||||
};
|
||||
|
||||
export function useIsEarlyAccess() {
|
||||
const { data } = useQueryImmutable(
|
||||
{
|
||||
query: getUserFeaturesQuery,
|
||||
},
|
||||
{
|
||||
use: [errorHandler],
|
||||
}
|
||||
);
|
||||
|
||||
return data?.currentUser?.features.includes(FeatureType.EarlyAccess) ?? false;
|
||||
}
|
||||
Reference in New Issue
Block a user