Skip to content

Commit

Permalink
feat: support add file sync with the folder has different name
Browse files Browse the repository at this point in the history
  • Loading branch information
ltaoo committed Jun 2, 2023
1 parent 7e3dd73 commit 075d6d3
Show file tree
Hide file tree
Showing 82 changed files with 3,707 additions and 2,666 deletions.
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
printWidth: 120,
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"devDependencies": {
"@types/node": "^18.15.11",
"@types/qs": "^6.9.7",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.21",
"tailwindcss": "^3.3.1",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions src/components/Article/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import {
ArticleCore,
ArticleHeadNode,
ArticleLineNode,
ArticleLinkNode,
ArticleListNode,
ArticleNodeType,
ArticleSectionNode,
ArticleTextNode,
} from "@/domains/article";
import { For } from "solid-js";
import { Dynamic } from "solid-js/web";

export function Article(props: { nodes: ArticleCore["children"] }) {
return (
<For each={props.nodes}>
{(node) => {
if (node.type === ArticleNodeType.Line) {
return <ArticleLine node={node as ArticleLineNode} />;
}
if (node.type === ArticleNodeType.Section) {
return <ArticleSection node={node as ArticleSectionNode} />;
}
return "unknown";
}}
</For>
);
}

export function ArticleLine(props: { node: ArticleLineNode }) {
return (
<p>
<For each={props.node.children}>
{(node) => {
if (node.type === ArticleNodeType.Head) {
return <ArticleHead node={node as ArticleHeadNode} />;
}
if (node.type === ArticleNodeType.Text) {
return <ArticleText node={node as ArticleTextNode} />;
}
if (node.type === ArticleNodeType.Link) {
return <ArticleLink node={node as ArticleLinkNode} />;
}
if (node.type === ArticleNodeType.List) {
return <ArticleList node={node as ArticleListNode} />;
}
return null;
}}
</For>
</p>
);
}

export function ArticleSection(props: { node: ArticleSectionNode }) {
return (
<div class="mt-4">
<For each={props.node.children}>
{(node) => {
return <ArticleLine node={node} />;
}}
</For>
</div>
);
}

export function ArticleHead(props: { node: ArticleHeadNode }) {
const {
node: { text, level, color },
} = props;

const elements = {
1: (
<h1 class="text-3xl border border-b" style={{ color }}>
{text}
</h1>
),
2: (
<h2 class="text-2xl border border-b" style={{ color }}>
{text}
</h2>
),
3: (
<h3 class="text-xl border border-b" style={{ color }}>
{text}
</h3>
),
};

return (
<>
<Dynamic component={elements[level]} />
</>
);
}

export function ArticleText(props: { node: ArticleTextNode }) {
const {
node: { color, text },
} = props;
return <span style={{ color }}>{text}</span>;
}

export function ArticleLink(props: { node: ArticleLinkNode }) {
const {
node: { text, href },
} = props;
return <a href={href}>{text}</a>;
}

export function ArticleList(props: { node: ArticleListNode }) {
const {
node: { children },
} = props;
return (
<ol>
<For each={children}>
{(node) => {
return (
<li>
<ArticleLine node={node} />
</li>
);
}}
</For>
</ol>
);
}
35 changes: 0 additions & 35 deletions src/components/CopyIcon/index.tsx

This file was deleted.

43 changes: 19 additions & 24 deletions src/components/DriveCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file 云盘卡片
*/
import { For, Show, createSignal } from "solid-js";
import { MoreHorizontal, Loader } from "lucide-solid";
import { MoreHorizontal, Loader, Apple, ArrowBigDown, RefreshCcw, Edit3, Download } from "lucide-solid";

import { Application } from "@/domains/app";
import { Drive } from "@/domains/drive";
Expand All @@ -14,7 +14,7 @@ import { LazyImage } from "@/components/LazyImage";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Progress } from "@/components/ui/progress";
import { Modal } from "@/components/SingleModal";
import { Dialog } from "@/components/ui/dialog";
import { DropdownMenu } from "@/components/ui/dropdown-menu";
import { InputCore } from "@/domains/ui/input";
import { ButtonCore } from "@/domains/ui/button";
Expand All @@ -33,27 +33,30 @@ export const DriveCard = (props: { app: Application; store: Drive }) => {
items: [
new MenuItemCore({
label: "签到",
icon: <Apple class="mr-2 w-4 h-4" />,
onClick() {
drive.checkIn();
dropdown.hide();
},
}),
new MenuItemCore({
label: "导出",
icon: <Download class="mr-2 w-4 h-4" />,
onClick() {
drive.export();
},
}),
new MenuItemCore({
label: "刷新",
icon: <RefreshCcw class="mr-2 w-4 h-4" />,
onClick() {
drive.refresh();
},
}),
new MenuItemCore({
label: "修改 refresh_token",
icon: <Edit3 class="mr-2 w-4 h-4" />,
onClick() {
console.log("修改 refresh_token");
dropdown.hide();
},
}),
Expand All @@ -62,14 +65,14 @@ export const DriveCard = (props: { app: Application; store: Drive }) => {
const progress = new ProgressCore({ value: drive.state.used_percent });
const input1 = new InputCore();
const input2 = new InputCore();
const button2 = new ButtonCore({
const analysisBtn = new ButtonCore({
onClick() {
if (!drive.state.initialized) {
foldersModal.show();
drive.fetch({ file_id: "root", name: "文件" });
return;
}
drive.startScrape(true);
drive.startScrape();
},
});
const button3 = new ButtonCore({
Expand Down Expand Up @@ -134,7 +137,7 @@ export const DriveCard = (props: { app: Application; store: Drive }) => {
// const drive_ref = useRef(new Drive({ id }));

return (
<div class="relative p-4 bg-white rounded-xl shadow-xl shadow-blue-200 border border-blue-400">
<div class="relative p-4 bg-white rounded-xl">
<div>
<div class="">
<div class="absolute top-2 right-2">
Expand All @@ -145,19 +148,15 @@ export const DriveCard = (props: { app: Application; store: Drive }) => {
</DropdownMenu>
</div>
<div class="flex">
<LazyImage
class="overflow-hidden w-16 h-16 mr-4 rounded"
src={avatar()}
alt={name()}
/>
<LazyImage class="overflow-hidden w-16 h-16 mr-4 rounded" src={avatar()} alt={name()} />
<div>
<div class="text-xl">{name()}</div>
<div class="flex items-center space-x-2">
<Progress class="" store={progress} />
{used_size()}/{total_size()}
</div>
<div class="flex items-center mt-4 space-x-2">
<Button variant="subtle" size="sm" store={button2}>
<Button variant="subtle" size="sm" store={analysisBtn}>
<Show when={loading()}>
<Loader class="w-4 h-4 animate-spin" />
</Show>
Expand All @@ -171,7 +170,7 @@ export const DriveCard = (props: { app: Application; store: Drive }) => {
</div>
</div>
</div>
<Modal title={name()} store={foldersModal}>
<Dialog title={name()} store={foldersModal}>
<div class="text-center">请先选择一个文件夹作为索引根目录</div>
<Show
when={folderColumns().length > 0}
Expand All @@ -187,10 +186,7 @@ export const DriveCard = (props: { app: Application; store: Drive }) => {
<For each={folderColumns()}>
{(column) => {
return (
<Show
when={column.length > 0}
fallback={<div>该文件夹没有文件</div>}
>
<Show when={column.length > 0} fallback={<div>该文件夹没有文件</div>}>
<div class="px-2 border-r-2">
<For each={column}>
{(folder) => {
Expand All @@ -200,8 +196,7 @@ export const DriveCard = (props: { app: Application; store: Drive }) => {
<div
class="p-2 cursor-pointer hover:bg-slate-300"
classList={{
"bg-slate-200":
file_id === values().root_folder_id,
"bg-slate-200": file_id === values().root_folder_id,
}}
onClick={() => {
drive.inputRootFolder(folder);
Expand All @@ -221,15 +216,15 @@ export const DriveCard = (props: { app: Application; store: Drive }) => {
</For>
</div>
</Show>
</Modal>
<Modal title="添加文件夹" store={createFolderModal}>
</Dialog>
<Dialog title="添加文件夹" store={createFolderModal}>
<div>
<Input store={input1} />
</div>
</Modal>
<Modal title="修改 refresh_token" store={refreshTokenModal}>
</Dialog>
<Dialog title="修改 refresh_token" store={refreshTokenModal}>
<Input store={input2} />
</Modal>
</Dialog>
</div>
);
};
Loading

0 comments on commit 075d6d3

Please sign in to comment.