Skip to content

Commit

Permalink
Merge pull request #539 from flocon-trpg/main
Browse files Browse the repository at this point in the history
  • Loading branch information
kizahasi authored Feb 21, 2023
2 parents d5724d7 + ae521ef commit f9db5c3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 34 deletions.
2 changes: 1 addition & 1 deletion apps/web-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flocon-trpg/web-server",
"version": "0.8.8",
"version": "0.8.9",
"description": "Flocon Web server",
"license": "MIT",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ import { ItemType } from 'antd/lib/menu/hooks/useItems';
import classNames from 'classnames';
import { produce } from 'immer';
import {
Provider,
useAtom as useAtomCore,
useAtomValue as useAtomValueCore,
useSetAtom as useSetAtomCore,
} from 'jotai/react';
import { Atom, PrimitiveAtom, atom, createStore } from 'jotai/vanilla';
import { Atom, PrimitiveAtom, atom, createStore, getDefaultStore } from 'jotai/vanilla';
import React from 'react';
import { useDeepCompareEffect, useLatest } from 'react-use';
import { VirtuosoGrid } from 'react-virtuoso';
Expand Down Expand Up @@ -232,10 +231,8 @@ export type Props = {
}[];
};

const defaultJotaiStore = createStore();

const defaultProps: Props = {
jotaiStore: defaultJotaiStore,
jotaiStore: getDefaultStore(),
files: [],
height: null,
isProtected: () => false,
Expand Down Expand Up @@ -2533,12 +2530,9 @@ const FileBrowserWithoutJotaiProvider: React.FC<Props> = props => {

/** 汎用的なファイルブラウザー(ファイルマネージャ)です。 */
export const FileBrowser: React.FC<Props> = props => {
// もしProvider.scopeがない場合、jotaiは最も近いProviderにアクセスするため、useWebConfigなどが常にnullishとなってしまう。それを防ぐため、scopeを用いている。
return (
<JotaiStoreContext.Provider value={props.jotaiStore}>
<Provider store={props.jotaiStore}>
<FileBrowserWithoutJotaiProvider {...props} />
</Provider>
<FileBrowserWithoutJotaiProvider {...props} />
</JotaiStoreContext.Provider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,13 @@ export const UploaderFileBrowser: React.FC<Props> = ({
height,
}: Props) => {
const [{ data: serverInfo }] = useQuery({ query: GetServerInfoDocument });
const isEmbeddedUploaderDisabled = serverInfo?.result.uploaderEnabled !== true;
/** `true` ならば enabled、`false` ならば disabled、nullish ならば判定中だということを示します。 */
const isEmbeddedUploaderEnabled = serverInfo?.result.uploaderEnabled;
const firebaseStorageFiles = useFirebaseStorageFiles(onSelect);
const floconUploaderFiles = useFloconUploaderFiles(onSelect, isEmbeddedUploaderDisabled);
const floconUploaderFiles = useFloconUploaderFiles(
onSelect,
isEmbeddedUploaderEnabled !== true
);
const [firebaseStorageUploaderModalState, setFirebaseStorageUploaderModalState] =
React.useState<{ storageType: StorageType; folderPath: readonly string[] }>();
const [floconUploaderModalState, setFloconUploaderModalState] = React.useState<{
Expand Down Expand Up @@ -477,28 +481,56 @@ export const UploaderFileBrowser: React.FC<Props> = ({
push(firebaseStorageFiles.public, [uploaderTypeFolderName.publicFirebaseStorage]);
push(firebaseStorageFiles.unlisted, [uploaderTypeFolderName.unlistedFirebaseStorage]);

if (isEmbeddedUploaderDisabled) {
result.push(
{
path: [uploaderTypeFolderName.publicApiServer],
element: <div style={style}>設定によって無効化されています。</div>,
},
{
path: [uploaderTypeFolderName.unlistedApiServer],
element: <div style={style}>設定によって無効化されています。</div>,
}
);
} else if (floconUploaderFiles == null) {
result.push(
{
path: [uploaderTypeFolderName.publicApiServer],
element: <div style={style}>読み込み中です…</div>,
},
{
path: [uploaderTypeFolderName.unlistedApiServer],
element: <div style={style}>読み込み中です…</div>,
switch (isEmbeddedUploaderEnabled) {
case null:
case undefined: {
result.push(
{
path: [uploaderTypeFolderName.publicApiServer],
element: (
<div style={style}>
内蔵アップローダーが有効かどうかを確認しています…
</div>
),
},
{
path: [uploaderTypeFolderName.unlistedApiServer],
element: (
<div style={style}>
内蔵アップローダーが有効かどうかを確認しています…
</div>
),
}
);
break;
}
case false: {
result.push(
{
path: [uploaderTypeFolderName.publicApiServer],
element: <div style={style}>設定によって無効化されています。</div>,
},
{
path: [uploaderTypeFolderName.unlistedApiServer],
element: <div style={style}>設定によって無効化されています。</div>,
}
);
break;
}
case true: {
if (floconUploaderFiles == null) {
result.push(
{
path: [uploaderTypeFolderName.publicApiServer],
element: <div style={style}>読み込み中です…</div>,
},
{
path: [uploaderTypeFolderName.unlistedApiServer],
element: <div style={style}>読み込み中です…</div>,
}
);
}
);
}
}

return result;
Expand All @@ -507,7 +539,7 @@ export const UploaderFileBrowser: React.FC<Props> = ({
firebaseStorageFiles.unlisted,
firebaseUser,
floconUploaderFiles,
isEmbeddedUploaderDisabled,
isEmbeddedUploaderEnabled,
]);

const jotaiStore = useConstant(() => createStore());
Expand Down

0 comments on commit f9db5c3

Please sign in to comment.