Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Daishan Peng <[email protected]>
  • Loading branch information
StrongMonkey committed Sep 13, 2024
1 parent 5254c8f commit 9daf2ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 45 deletions.
27 changes: 1 addition & 26 deletions components/knowledge/Notion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import {
TableRow,
} from '@nextui-org/react';
import React, { useContext, useEffect, useState } from 'react';
import {
getNotionFiles,
isNotionConfigured,
runNotionSync,
} from '@/actions/knowledge/notion';
import { getNotionFiles, isNotionConfigured } from '@/actions/knowledge/notion';
import { CiSearch, CiShare1 } from 'react-icons/ci';
import { EditContext } from '@/contexts/edit';
import { importFiles } from '@/actions/knowledge/filehelper';
Expand All @@ -29,23 +25,17 @@ import { syncFiles } from '@/actions/knowledge/tool';
interface NotionFileModalProps {
isOpen: boolean;
onClose: () => void;
isSyncing: boolean;
setIsSyncing: React.Dispatch<React.SetStateAction<boolean>>;
notionConfigured: boolean;
setNotionConfigured: React.Dispatch<React.SetStateAction<boolean>>;
syncError: string;
setSyncError: React.Dispatch<React.SetStateAction<string>>;
}

export const NotionFileModal = ({
isOpen,
onClose,
notionConfigured,
setNotionConfigured,
isSyncing,
setIsSyncing,
syncError,
setSyncError,
}: NotionFileModalProps) => {
const { droppedFiles, ensureImportedFiles } = useContext(EditContext);
const [searchQuery, setSearchQuery] = useState<string>('');
Expand Down Expand Up @@ -92,21 +82,6 @@ export const NotionFileModal = ({
onClose();
};

const syncNotion = async () => {
setIsSyncing(true);
try {
const isConfigured = await isNotionConfigured();
await runNotionSync(isConfigured);
setNotionConfigured(isConfigured);
setNotionFiles(await getNotionFiles());
setSyncError('');
} catch (e) {
setSyncError((e as Error).toString());
} finally {
setIsSyncing(false);
}
};

const handleSelectedFileChange = (selected: any) => {
if (selected === 'all') {
setSelectedFile(Array.from(notionFiles.keys()));
Expand Down
29 changes: 10 additions & 19 deletions components/knowledge/OneDrive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
TableColumn,
TableHeader,
TableRow,
useDisclosure,
} from '@nextui-org/react';
import React, { useContext, useEffect, useState } from 'react';
import {
Expand All @@ -23,7 +22,7 @@ import {
runOneDriveSync,
syncSharedLink,
} from '@/actions/knowledge/onedrive';
import { CiSearch, CiShare1 } from 'react-icons/ci';
import { CiShare1 } from 'react-icons/ci';
import { EditContext } from '@/contexts/edit';
import { importFiles } from '@/actions/knowledge/filehelper';
import { Link } from '@nextui-org/react';
Expand Down Expand Up @@ -51,7 +50,6 @@ export const OnedriveFileModal = ({
setSyncError,
}: OnedriveFileModalProps) => {
const { droppedFiles, ensureImportedFiles } = useContext(EditContext);
const [searchQuery, setSearchQuery] = useState<string>('');
const [importing, setImporting] = useState(false);
const [sharedLink, setSharedLink] = useState<string>('');
const [isClearing, setIsClearing] = useState(false);
Expand Down Expand Up @@ -221,22 +219,15 @@ export const OnedriveFileModal = ({
<TableColumn>Link</TableColumn>
</TableHeader>
<TableBody
items={Array.from(onedriveFiles.entries())
.sort((a, b) => {
if (a[1].displayName < b[1].displayName) {
return -1;
} else if (a[1].displayName > b[1].displayName) {
return 1;
} else {
return 0;
}
})
.filter(([_, file]) => {
if (!searchQuery) return true;
return file.displayName
.toLowerCase()
.includes(searchQuery.toLowerCase());
})}
items={Array.from(onedriveFiles.entries()).sort((a, b) => {
if (a[1].displayName < b[1].displayName) {
return -1;
} else if (a[1].displayName > b[1].displayName) {
return 1;
} else {
return 0;
}
})}
>
{([key, value]) => (
<TableRow key={key}>
Expand Down

0 comments on commit 9daf2ae

Please sign in to comment.