mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix: reset file inputs after import
This commit is contained in:
@@ -24,7 +24,7 @@ import { treeDataAtom } from "@/features/page/tree/atoms/tree-data-atom.ts";
|
|||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { buildTree } from "@/features/page/tree/utils";
|
import { buildTree } from "@/features/page/tree/utils";
|
||||||
import { IPage } from "@/features/page/types/page.types.ts";
|
import { IPage } from "@/features/page/types/page.types.ts";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { ConfluenceIcon } from "@/components/icons/confluence-icon.tsx";
|
import { ConfluenceIcon } from "@/components/icons/confluence-icon.tsx";
|
||||||
import { getFileImportSizeLimit, isCloud } from "@/lib/config.ts";
|
import { getFileImportSizeLimit, isCloud } from "@/lib/config.ts";
|
||||||
@@ -84,6 +84,12 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
|||||||
const [fileTaskId, setFileTaskId] = useState<string | null>(null);
|
const [fileTaskId, setFileTaskId] = useState<string | null>(null);
|
||||||
const emit = useQueryEmit();
|
const emit = useQueryEmit();
|
||||||
|
|
||||||
|
const markdownFileRef = useRef<() => void>(null);
|
||||||
|
const htmlFileRef = useRef<() => void>(null);
|
||||||
|
const notionFileRef = useRef<() => void>(null);
|
||||||
|
const confluenceFileRef = useRef<() => void>(null);
|
||||||
|
const zipFileRef = useRef<() => void>(null);
|
||||||
|
|
||||||
const canUseConfluence = isCloud() || workspace?.hasLicenseKey;
|
const canUseConfluence = isCloud() || workspace?.hasLicenseKey;
|
||||||
|
|
||||||
const handleZipUpload = async (selectedFile: File, source: string) => {
|
const handleZipUpload = async (selectedFile: File, source: string) => {
|
||||||
@@ -116,6 +122,15 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setFileTaskId(importTask.id);
|
setFileTaskId(importTask.id);
|
||||||
|
|
||||||
|
// Reset file input after successful upload
|
||||||
|
if (source === "notion" && notionFileRef.current) {
|
||||||
|
notionFileRef.current();
|
||||||
|
} else if (source === "confluence" && confluenceFileRef.current) {
|
||||||
|
confluenceFileRef.current();
|
||||||
|
} else if (source === "generic" && zipFileRef.current) {
|
||||||
|
zipFileRef.current();
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Failed to upload import file", err);
|
console.log("Failed to upload import file", err);
|
||||||
notifications.update({
|
notifications.update({
|
||||||
@@ -243,6 +258,10 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
|||||||
setTreeData(fullTree);
|
setTreeData(fullTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset file inputs after successful upload
|
||||||
|
if (markdownFileRef.current) markdownFileRef.current();
|
||||||
|
if (htmlFileRef.current) htmlFileRef.current();
|
||||||
|
|
||||||
const pageCountText =
|
const pageCountText =
|
||||||
pageCount === 1 ? `1 ${t("page")}` : `${pageCount} ${t("pages")}`;
|
pageCount === 1 ? `1 ${t("page")}` : `${pageCount} ${t("pages")}`;
|
||||||
|
|
||||||
@@ -272,7 +291,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SimpleGrid cols={2}>
|
<SimpleGrid cols={2}>
|
||||||
<FileButton onChange={handleFileUpload} accept=".md" multiple>
|
<FileButton onChange={handleFileUpload} accept=".md" multiple resetRef={markdownFileRef}>
|
||||||
{(props) => (
|
{(props) => (
|
||||||
<Button
|
<Button
|
||||||
justify="start"
|
justify="start"
|
||||||
@@ -285,7 +304,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
|||||||
)}
|
)}
|
||||||
</FileButton>
|
</FileButton>
|
||||||
|
|
||||||
<FileButton onChange={handleFileUpload} accept="text/html" multiple>
|
<FileButton onChange={handleFileUpload} accept="text/html" multiple resetRef={htmlFileRef}>
|
||||||
{(props) => (
|
{(props) => (
|
||||||
<Button
|
<Button
|
||||||
justify="start"
|
justify="start"
|
||||||
@@ -301,6 +320,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
|||||||
<FileButton
|
<FileButton
|
||||||
onChange={(file) => handleZipUpload(file, "notion")}
|
onChange={(file) => handleZipUpload(file, "notion")}
|
||||||
accept="application/zip"
|
accept="application/zip"
|
||||||
|
resetRef={notionFileRef}
|
||||||
>
|
>
|
||||||
{(props) => (
|
{(props) => (
|
||||||
<Button
|
<Button
|
||||||
@@ -316,6 +336,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
|||||||
<FileButton
|
<FileButton
|
||||||
onChange={(file) => handleZipUpload(file, "confluence")}
|
onChange={(file) => handleZipUpload(file, "confluence")}
|
||||||
accept="application/zip"
|
accept="application/zip"
|
||||||
|
resetRef={confluenceFileRef}
|
||||||
>
|
>
|
||||||
{(props) => (
|
{(props) => (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
@@ -352,6 +373,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
|||||||
<FileButton
|
<FileButton
|
||||||
onChange={(file) => handleZipUpload(file, "generic")}
|
onChange={(file) => handleZipUpload(file, "generic")}
|
||||||
accept="application/zip"
|
accept="application/zip"
|
||||||
|
resetRef={zipFileRef}
|
||||||
>
|
>
|
||||||
{(props) => (
|
{(props) => (
|
||||||
<Group justify="center">
|
<Group justify="center">
|
||||||
|
|||||||
Reference in New Issue
Block a user