Skip to content

Commit

Permalink
feat: v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuqi committed Aug 10, 2020
1 parent 46c6cde commit 3921f39
Show file tree
Hide file tree
Showing 16 changed files with 2,029 additions and 1,836 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Neural
<h1 align="center">Neural</h1>

<p align="center">
<img src="./sample/logo256.png" width="200">
</p>

## Start

Expand All @@ -11,3 +15,23 @@ yarn start
```
yarn build
```

## How to use

Create

```
> ${tag}
```

Query

```
${tag}
```

## Sample

<p>
<img src="./sample/main.png" width="600">
</p>
5 changes: 3 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0. SW + Notification
1. Tray(系统托盘)
2. 开机自启动
3. onQiut
3. autodeploy
4. ? 查看使用说明
5. @all 查看全部列表
8 changes: 7 additions & 1 deletion public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ const registWindowEvent = () => {
});
};

app.on("ready", createWindow);
app.on("ready", () => {
createWindow();
});

app.on("activate", () => {
if (mainWindow) {
mainWindow.show();
}
});

app.on("before-quit", () => {
app.exit();
});
Binary file added sample/logo256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import TagList from "./components/TagList";
import TagDetail from "./components/TagDetail";
import neuralDB, { Tag } from "./utils/Database";
import { SizeType, resizeTo, shake } from "./utils/Window";
import Timer from "./utils/Timer";
import "./App.scss";

const WAIT = 500;
const timer = new Timer();

const Pattern = {
isEmpty: (input: string) => input.trim() === ">" || input.trim() === "",
Expand All @@ -18,6 +20,7 @@ const App: FC = () => {
let [inputVal, setInputVal] = useState("");
let [selectedTag, setSelectedTag] = useState<Tag | null>(null);
let [tagList, setTaglist] = useState<Array<Tag>>([]);
timer.start(setInputVal);

let createTag = (input: string) => {
input = input.trim();
Expand Down
26 changes: 21 additions & 5 deletions src/components/TagDetail.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,30 @@
text-align: right;
border-left: 1px solid $light-grey;

.ant-statistic-title {
.tag-is-done {
font-size: 24px;
color: $blue;
}

.countdown-title {
font-size: 14px;
color: $grey;
}

.ant-statistic-content {
font-size: 16px;
font-weight: bold;
color: $dark-grey;
.countdown-content {
.countdown-button-group {
padding-top: 4px;

.ant-btn + .ant-btn {
margin-left: 4px;
}
}

.ant-statistic-content {
font-size: 16px;
font-weight: bold;
color: $dark-grey;
}
}
}
}
Expand All @@ -69,6 +84,7 @@
font-size: 14px;
color: $grey;
}

.wikis-content {
margin-top: 1px;

Expand Down
101 changes: 92 additions & 9 deletions src/components/TagDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import {
CheckOutlined,
LinkOutlined,
CloseOutlined,
SmileFilled,
SmileOutlined,
FrownOutlined,
} from "@ant-design/icons";
import neuralDB, { Tag } from "../utils/Database";
import neuralDB, { Tag, TagStatus } from "../utils/Database";
import { shake } from "../utils/Window";
import tagDefault from "../configs/tag-default.json";
import "./TagDetail.scss";

const { Countdown } = Statistic;
Expand All @@ -29,6 +33,9 @@ interface ITagDetailProps {
const TagDetail: FC<ITagDetailProps> = (tagDetailProps: ITagDetailProps) => {
let { selectedTag, onDelete, onUpdate } = tagDetailProps;

/************************************************************************************************
* Wikis
************************************************************************************************/
let [wikis, setWikis] = useState(selectedTag.wikis || []);
let [wikiUrl, setWikiUrl] = useState("");

Expand Down Expand Up @@ -108,9 +115,20 @@ const TagDetail: FC<ITagDetailProps> = (tagDetailProps: ITagDetailProps) => {
</div>
);

/************************************************************************************************
* Wikis End
************************************************************************************************/

/************************************************************************************************
* Descriptions
************************************************************************************************/
let [descriptions, setDescriptions] = useState(selectedTag.descriptions || "");
let [isEditing, setIsEditing] = useState(false);

let { expires, status } = selectedTag;
let isExpired = expires! <= Date.now();
let isDone = status === TagStatus.DONE;

let handleChangeDescriptions = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
setDescriptions(e.target.value);
};
Expand All @@ -136,6 +154,37 @@ const TagDetail: FC<ITagDetailProps> = (tagDetailProps: ITagDetailProps) => {
setIsEditing(false);
};

let handleDone = () => {
neuralDB.ready(async () => {
try {
let tag: Tag = Object.assign({}, selectedTag, {
status: TagStatus.DONE,
});
neuralDB.upsert_tag(tag);
onUpdate(tag);
} catch (e) {
shake();
console.log(e);
}
});
};

let handleDelay = () => {
neuralDB.ready(async () => {
try {
let tag: Tag = Object.assign({}, selectedTag, {
expires: Date.now() + tagDefault.expires,
status: TagStatus.PENDING,
});
neuralDB.upsert_tag(tag);
onUpdate(tag);
} catch (e) {
shake();
console.log(e);
}
});
};

let descriptionsRow = (
<div className="row-descriptions-expires">
<div className="descriptions">
Expand Down Expand Up @@ -171,10 +220,51 @@ const TagDetail: FC<ITagDetailProps> = (tagDetailProps: ITagDetailProps) => {
)}
</div>
</div>
<Countdown className="countdown" title="Expires" value={selectedTag.expires} />

<div className="countdown">
{isDone ? (
<SmileFilled className="tag-is-done" />
) : (
<div>
<div className="countdown-title">Expires</div>
<div className="countdown-content">
{isExpired ? (
<div className="countdown-button-group">
<Button
type="primary"
icon={<SmileOutlined />}
size="small"
onClick={handleDone}
/>
<Button
type="primary"
danger
icon={<FrownOutlined />}
size="small"
onClick={handleDelay}
/>
</div>
) : (
<Countdown value={selectedTag.expires} />
)}
</div>
</div>
)}
</div>
</div>
);

/************************************************************************************************
* Descriptions End
************************************************************************************************/

useEffect(() => {
setWikiUrl("");
setWikis(selectedTag.wikis || []);
setIsEditing(false);
setDescriptions(selectedTag.descriptions || "");
}, [selectedTag]);

let handleDeleteTag = () => {
neuralDB.ready(async () => {
try {
Expand All @@ -188,13 +278,6 @@ const TagDetail: FC<ITagDetailProps> = (tagDetailProps: ITagDetailProps) => {
});
};

useEffect(() => {
setWikiUrl("");
setWikis(selectedTag.wikis || []);
setIsEditing(false);
setDescriptions(selectedTag.descriptions || "");
}, [selectedTag]);

return (
<div className="tag-detail">
<div className="tag-name">{selectedTag.name}</div>
Expand Down
4 changes: 3 additions & 1 deletion src/configs/tag-default.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"expires": 86400000,
"expireCheckInterval": 1800000
"@comment_expires": "1d",
"expireCheckInterval": 10800000,
"@comment_expireCheckInterval": "3h"
}
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import Event from "./utils/Event";

declare global {
interface Window {
Expand All @@ -10,4 +11,5 @@ declare global {
}
}

Event.regist();
ReactDOM.render(<App />, document.getElementById("root"));
17 changes: 14 additions & 3 deletions src/utils/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ export enum EventType {
DeleteTag,
}

export enum TagStatus {
PENDING = "pending",
DONE = "done",
}

export interface Tag {
id?: string;
name: string;
descriptions?: string;
wikis?: Array<string>;
expires?: number;
status?: TagStatus;
}

export interface Observer {
Expand Down Expand Up @@ -140,9 +146,12 @@ export class NeuralDB {
tag.id = tag.id || id;

// 默认过期时间
let expires = new Date().getTime() + tagDefault.expires;
let expires = Date.now() + tagDefault.expires;
tag.expires = tag.expires || expires;

// status
tag.status = tag.status || TagStatus.PENDING;

let transaction = this.db_ins.transaction(NeuralDB.STORE_TAG, "readwrite");
let store = transaction.objectStore(NeuralDB.STORE_TAG);

Expand Down Expand Up @@ -264,12 +273,14 @@ export class NeuralDB {
return new Promise((res, rej) => {
let list: Array<Tag> = [];
let cursorRequest = store.openCursor();
let currentTime = new Date().getTime();
let currentTime = Date.now();

cursorRequest.onsuccess = function (event: any) {
let cursor = event.target.result;
if (!cursor) return res(list);
if (cursor.value.expires <= currentTime) list.push(cursor.value);
if (cursor.value.status === TagStatus.PENDING && cursor.value.expires <= currentTime) {
list.push(cursor.value);
}
cursor.continue();
};
cursorRequest.onerror = (err: any) => rej(err);
Expand Down
18 changes: 18 additions & 0 deletions src/utils/Event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function unReload() {
window.onkeydown = function (e: any) {
const ev = window.event || e;
const code = ev.keyCode || ev.which;
if ((ev.ctrlKey || ev.metaKey) && code === 82) {
console.warn("Reload is not allowed!");
return false;
}
};
}

export function regist() {
unReload();
}

export default {
regist,
};
Loading

0 comments on commit 3921f39

Please sign in to comment.