From b2424aab5ea4c516a292783944ad999be3fe78e6 Mon Sep 17 00:00:00 2001 From: Scott Cytacki Date: Tue, 12 Nov 2024 11:14:20 -0500 Subject: [PATCH] use new cfm openLocalFileWithConfirmation simplify drop handle, it no longer needs to load the file content itself --- v3/package-lock.json | 15 ++++++++------- v3/package.json | 2 +- v3/src/components/app.tsx | 10 ++++------ v3/src/hooks/use-drop-handler.ts | 24 ++---------------------- 4 files changed, 15 insertions(+), 36 deletions(-) diff --git a/v3/package-lock.json b/v3/package-lock.json index e57796a2f..399e61655 100644 --- a/v3/package-lock.json +++ b/v3/package-lock.json @@ -16,7 +16,7 @@ "@codemirror/commands": "^6.7.1", "@codemirror/language": "^6.10.3", "@codemirror/view": "^6.34.1", - "@concord-consortium/cloud-file-manager": "^2.0.0-pre.6", + "@concord-consortium/cloud-file-manager": "^2.0.0-pre.7", "@concord-consortium/mobx-state-tree": "^6.0.0-cc.1", "@concord-consortium/slate-editor": "^0.10.1", "@dnd-kit/core": "^6.1.0", @@ -2232,9 +2232,10 @@ } }, "node_modules/@concord-consortium/cloud-file-manager": { - "version": "2.0.0-pre.6", - "resolved": "https://registry.npmjs.org/@concord-consortium/cloud-file-manager/-/cloud-file-manager-2.0.0-pre.6.tgz", - "integrity": "sha512-jsgZgeBxSY8+SX0TYnXo1VjANrUQl/cv3rcRviHa8WBAwMbiomUDU32p/kaIdrH28U3OZE75JSFxd1jDuIdMlg==", + "version": "2.0.0-pre.7", + "resolved": "https://registry.npmjs.org/@concord-consortium/cloud-file-manager/-/cloud-file-manager-2.0.0-pre.7.tgz", + "integrity": "sha512-IMhSNkBngE4S6QOeFHv7jweQW/szCgxiesO9GztTgfTYlPrENYvxr8H/SgeocCRiq11l3xtrizPEjZ0xDcjKmQ==", + "license": "MIT", "dependencies": { "@concord-consortium/lara-interactive-api": "^1.9.4", "@concord-consortium/token-service": "^2.1.0", @@ -25447,9 +25448,9 @@ "optional": true }, "@concord-consortium/cloud-file-manager": { - "version": "2.0.0-pre.6", - "resolved": "https://registry.npmjs.org/@concord-consortium/cloud-file-manager/-/cloud-file-manager-2.0.0-pre.6.tgz", - "integrity": "sha512-jsgZgeBxSY8+SX0TYnXo1VjANrUQl/cv3rcRviHa8WBAwMbiomUDU32p/kaIdrH28U3OZE75JSFxd1jDuIdMlg==", + "version": "2.0.0-pre.7", + "resolved": "https://registry.npmjs.org/@concord-consortium/cloud-file-manager/-/cloud-file-manager-2.0.0-pre.7.tgz", + "integrity": "sha512-IMhSNkBngE4S6QOeFHv7jweQW/szCgxiesO9GztTgfTYlPrENYvxr8H/SgeocCRiq11l3xtrizPEjZ0xDcjKmQ==", "requires": { "@concord-consortium/lara-interactive-api": "^1.9.4", "@concord-consortium/token-service": "^2.1.0", diff --git a/v3/package.json b/v3/package.json index eae82f01b..60e76d4dc 100644 --- a/v3/package.json +++ b/v3/package.json @@ -191,7 +191,7 @@ "@codemirror/commands": "^6.7.1", "@codemirror/language": "^6.10.3", "@codemirror/view": "^6.34.1", - "@concord-consortium/cloud-file-manager": "^2.0.0-pre.6", + "@concord-consortium/cloud-file-manager": "^2.0.0-pre.7", "@concord-consortium/mobx-state-tree": "^6.0.0-cc.1", "@concord-consortium/slate-editor": "^0.10.1", "@dnd-kit/core": "^6.1.0", diff --git a/v3/src/components/app.tsx b/v3/src/components/app.tsx index 86da0b925..c79a29113 100644 --- a/v3/src/components/app.tsx +++ b/v3/src/components/app.tsx @@ -4,7 +4,6 @@ import { CodapDndContext } from "../lib/dnd-kit/codap-dnd-context" import { Container } from "./container/container" import { ToolShelf } from "./tool-shelf/tool-shelf" import { kCodapAppElementId } from "./constants" -import { ICodapV2DocumentJson } from "../v2/codap-v2-types" import { MenuBar, kMenuBarElementId } from "./menu-bar/menu-bar" import { useCloudFileManager } from "../lib/use-cloud-file-manager" import { Logger } from "../lib/logger" @@ -13,7 +12,6 @@ import { addDefaultComponents } from "../models/codap/add-default-content" import {gDataBroker} from "../models/data/data-broker" import {IDataSet} from "../models/data/data-set" import { dataContextCountChangedNotification } from "../models/data/data-set-notifications" -import { IDocumentModelSnapshot } from "../models/document/document" import { IImportDataSetOptions } from "../models/document/document-content" import { ISharedDataSet } from "../models/shared/shared-data-set" import { getSharedModelManager } from "../models/tiles/tile-environment" @@ -37,7 +35,7 @@ registerTileTypes([]) export const App = observer(function App() { useKeyStates() - useCloudFileManager({ + const cfm = useCloudFileManager({ appOrMenuElemId: kMenuBarElementId }) @@ -57,9 +55,9 @@ export const App = observer(function App() { sharedData?.dataSet.completeSnapshot() }, []) - const handleImportDocument = useCallback((document: IDocumentModelSnapshot | ICodapV2DocumentJson) => { - appState.setDocument(document) - }, []) + const handleImportDocument = useCallback((file: File) => { + cfm?.client.openLocalFileWithConfirmation(file) + }, [cfm]) const handleUrlDrop = useCallback((url: string) => { const tile = appState.document.content?.createOrShowTile(kWebViewTileType) diff --git a/v3/src/hooks/use-drop-handler.ts b/v3/src/hooks/use-drop-handler.ts index c9441e2ff..8d5ab9212 100644 --- a/v3/src/hooks/use-drop-handler.ts +++ b/v3/src/hooks/use-drop-handler.ts @@ -1,27 +1,11 @@ import { useEffect, useRef } from "react" import { IDataSet } from "../models/data/data-set" -import { IDocumentModelSnapshot } from "../models/document/document" import { convertParsedCsvToDataSet, CsvParseResult, importCsvFile } from "../utilities/csv-import" -import { safeJsonParse } from "../utilities/js-utils" -import { ICodapV2DocumentJson } from "../v2/codap-v2-types" - -function importCodapDocument( - file: File | null, - onComplete: (document: IDocumentModelSnapshot | ICodapV2DocumentJson) => void -) { - const reader = new FileReader() - reader.onload = () => { - const document = reader.result && - safeJsonParse(reader.result as string) - document && onComplete(document) - } - file && reader.readAsText(file) -} export interface IDropHandler { selector: string onImportDataSet?: (data: IDataSet) => void - onImportDocument?: (document: IDocumentModelSnapshot | ICodapV2DocumentJson) => void + onImportDocument?: (file: File) => void onHandleUrlDrop?: (url: string) => void } export const useDropHandler = ({ @@ -39,10 +23,6 @@ export const useDropHandler = ({ function dropHandler(event: DragEvent) { - function onCompleteCodapImport(document: IDocumentModelSnapshot | ICodapV2DocumentJson) { - onImportDocument?.(document) - } - function onCompleteCsvImport(results: CsvParseResult, aFile: any) { const ds = convertParsedCsvToDataSet(results, aFile.name) onImportDataSet?.(ds) @@ -62,7 +42,7 @@ export const useDropHandler = ({ switch (extension) { case "codap": case "codap3": - importCodapDocument(file, onCompleteCodapImport) + file && onImportDocument?.(file) break case "csv": importCsvFile(file, onCompleteCsvImport)