mirror of
https://github.com/docmost/docmost.git
synced 2025-11-10 07:02:06 +10: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 { buildTree } from "@/features/page/tree/utils";
|
||||
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 { ConfluenceIcon } from "@/components/icons/confluence-icon.tsx";
|
||||
import { getFileImportSizeLimit, isCloud } from "@/lib/config.ts";
|
||||
@ -84,6 +84,12 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||
const [fileTaskId, setFileTaskId] = useState<string | null>(null);
|
||||
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 handleZipUpload = async (selectedFile: File, source: string) => {
|
||||
@ -116,6 +122,15 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||
});
|
||||
|
||||
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) {
|
||||
console.log("Failed to upload import file", err);
|
||||
notifications.update({
|
||||
@ -243,6 +258,10 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||
setTreeData(fullTree);
|
||||
}
|
||||
|
||||
// Reset file inputs after successful upload
|
||||
if (markdownFileRef.current) markdownFileRef.current();
|
||||
if (htmlFileRef.current) htmlFileRef.current();
|
||||
|
||||
const pageCountText =
|
||||
pageCount === 1 ? `1 ${t("page")}` : `${pageCount} ${t("pages")}`;
|
||||
|
||||
@ -272,7 +291,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||
return (
|
||||
<>
|
||||
<SimpleGrid cols={2}>
|
||||
<FileButton onChange={handleFileUpload} accept=".md" multiple>
|
||||
<FileButton onChange={handleFileUpload} accept=".md" multiple resetRef={markdownFileRef}>
|
||||
{(props) => (
|
||||
<Button
|
||||
justify="start"
|
||||
@ -285,7 +304,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||
)}
|
||||
</FileButton>
|
||||
|
||||
<FileButton onChange={handleFileUpload} accept="text/html" multiple>
|
||||
<FileButton onChange={handleFileUpload} accept="text/html" multiple resetRef={htmlFileRef}>
|
||||
{(props) => (
|
||||
<Button
|
||||
justify="start"
|
||||
@ -301,6 +320,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||
<FileButton
|
||||
onChange={(file) => handleZipUpload(file, "notion")}
|
||||
accept="application/zip"
|
||||
resetRef={notionFileRef}
|
||||
>
|
||||
{(props) => (
|
||||
<Button
|
||||
@ -316,6 +336,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||
<FileButton
|
||||
onChange={(file) => handleZipUpload(file, "confluence")}
|
||||
accept="application/zip"
|
||||
resetRef={confluenceFileRef}
|
||||
>
|
||||
{(props) => (
|
||||
<Tooltip
|
||||
@ -352,6 +373,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||
<FileButton
|
||||
onChange={(file) => handleZipUpload(file, "generic")}
|
||||
accept="application/zip"
|
||||
resetRef={zipFileRef}
|
||||
>
|
||||
{(props) => (
|
||||
<Group justify="center">
|
||||
|
||||
Reference in New Issue
Block a user