Skip to content

Commit

Permalink
fix: add compatibility for multiple Flare formats
Browse files Browse the repository at this point in the history
  • Loading branch information
rockbenben committed Mar 7, 2024
1 parent a738173 commit b433146
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/app/data-parser/flare/client.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import React, { useState, useEffect } from "react";
import { Input, Button, Typography, Row, Col, message, Radio } from "antd";
import { Input, Button, Typography, Row, Col, message, Radio, Flex } from "antd";
import { CopyOutlined } from "@ant-design/icons";
import { CopyToClipboard } from "react-copy-to-clipboard";

Expand All @@ -15,8 +15,8 @@ const FlareDataPage = () => {
const [rule, setRule] = useState("app"); // 新增状态变量用于存储当前选择的规则

useEffect(() => {
const appRegex = /^ - name: (.+)\n link: (.+)\n icon: (.+)\n desc: (.+)$/gm;
const bookmarkRegex = /^ - name: (.+)\n link: (.+)\n icon: (.+)\n category: "(.+)"$/gm;
const appRegex = /^\s*- name: (.+)\n\s*link: (.+)\n\s*icon: (.+)\n\s*desc: (.+)$/gm;
const bookmarkRegex = /^\s*- name: (.+)\n\s*link: (.+)\n\s*icon: (.+)\n\s*category: "(.+)"$/gm;

if (appRegex.test(inputData)) {
setCurrentFormat("app");
Expand Down Expand Up @@ -97,31 +97,34 @@ const FlareDataPage = () => {
<Title level={2}>Flare 书签解析工具</Title>
<Paragraph>用于将书签数据转换为 Flare 的格式。您可以选择“App”模式以解析应用列表,或“Bookmark”模式以解析书签列表,并可实现 app 和 bookmarks 间的互相转换。</Paragraph>

<Radio.Group value={rule} onChange={(e) => setRule(e.target.value)} style={{ marginBottom: "10px" }}>
<Radio.Button value="app">App</Radio.Button>
<Radio.Button value="bookmark">Bookmark</Radio.Button>
</Radio.Group>

<Input placeholder="指定 bookmarks 内的 category ID" value={categoryId} onChange={handleCategoryIdChange} style={{ marginBottom: "10px" }} />

<Row gutter={16}>
<Col span={12}>
<TextArea rows={6} value={inputData} onChange={handleInputChange} placeholder="在此粘贴源码" />
<Button type="text" onClick={parseFlareData} style={{ margin: "10px 0" }}>
解析数据
</Button>
<Button type="text" onClick={convertToBookmark} style={{ margin: "10px 0" }} disabled={currentFormat !== "app"}>
转换为 Bookmark 格式
</Button>
<Button type="text" onClick={convertToApp} style={{ margin: "10px 0" }} disabled={currentFormat !== "bookmark"}>
转换为 App 格式
</Button>
<Text type="secondary">输入书签:</Text>
<TextArea rows={6} value={inputData} onChange={handleInputChange} placeholder="在此粘贴书签数据" style={{ marginBottom: "10px" }} />
<Input placeholder="转换为 Bookmark 格式时,指定 category ID,比如 2" value={categoryId} onChange={handleCategoryIdChange} />
<Flex wrap="wrap" gap="small">
<Button type="primary" onClick={parseFlareData} style={{ margin: "10px 0" }}>
解析书签数据
</Button>
<Radio.Group value={rule} onChange={(e) => setRule(e.target.value)} style={{ margin: "15px 0" }}>
<Radio value="app">书签转 App</Radio>
<Radio value="bookmark">书签转 Bookmark</Radio>
</Radio.Group>
</Flex>
<Flex wrap="wrap" gap="small">
<Button type="dashed" onClick={convertToBookmark} disabled={currentFormat !== "app"}>
转换为 Bookmark 格式
</Button>
<Button type="dashed" onClick={convertToApp} disabled={currentFormat !== "bookmark"}>
转换为 App 格式
</Button>
</Flex>
</Col>
<Col span={12}>
<Text type="secondary">输出结果:</Text>
<TextArea rows={10} value={outputData} readOnly />
<TextArea rows={8} value={outputData} readOnly />
<CopyToClipboard text={outputData} onCopy={() => message.success("结果已复制到剪贴板")}>
<Button type="text" icon={<CopyOutlined />} style={{ margin: "10px 0" }}>
<Button icon={<CopyOutlined />} style={{ margin: "10px 0" }}>
复制结果
</Button>
</CopyToClipboard>
Expand Down

0 comments on commit b433146

Please sign in to comment.