Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
feat: add clearone feature
Browse files Browse the repository at this point in the history
  • Loading branch information
flytam committed Apr 30, 2023
1 parent 640b1bc commit 7b7552e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
31 changes: 30 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,39 @@ function App() {
}}
>
<Clear
type="one"
onClick={async () => {
await confirmDialog();
const ts = clipBoardList[activeIndexList[0]].timestamp;
if (ts) {
await confirmDialog({
title: "确认删除当前选中记录",
description: "清除后无法恢复,请确认是否继续",
});
clearOne(ts);
}
}}
sx={{
position: "fixed",
zIndex: 100,
right: "80px",
bottom: "20px",
}}
/>
<Clear
type="all"
onClick={async () => {
await confirmDialog({
title: "确认清除剪切板记录",
description: "清除后无法恢复,请确认是否继续",
});
clearAll();
}}
sx={{
position: "fixed",
zIndex: 100,
right: "20px",
bottom: "20px",
}}
/>

<FilterTab
Expand Down
20 changes: 11 additions & 9 deletions src/components/Clear.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { colors, IconButton, Tooltip } from "@mui/material";
import { colors, IconButton, SxProps, Theme, Tooltip } from "@mui/material";
import { FC } from "react";
import { ClearAll } from "@mui/icons-material";
import { ClearAll, Clear as ClearIcon } from "@mui/icons-material";

export const Clear: FC<{
onClick: () => void;
}> = ({ onClick }) => {
sx?: SxProps<Theme>;
type: "all" | "one";
}> = ({ onClick, sx = {}, type }) => {
return (
<Tooltip title="清空所有记录">
<Tooltip
title={type === "all" ? "清空所有记录" : "删除当前选中记录"}
placement="left-start"
>
<IconButton
component="label"
onClick={onClick}
sx={{
position: "fixed",
zIndex: 100,
right: "20px",
bottom: "20px",
background: colors.grey[300],
...sx,
}}
>
<ClearAll />
{type === "all" ? <ClearAll /> : <ClearIcon />}
</IconButton>
</Tooltip>
);
Expand Down
14 changes: 10 additions & 4 deletions src/utils/confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { useBoolean } from "ahooks";
import { useEffect } from "react";
import ReactDOM from "react-dom/client";

export const confirmDialog = () => {
interface Options {
title: string;
description?: string;
}

export const confirmDialog = (options: Options) => {
return new Promise<void>((resolve, reject) => {
const Ele = () => {
const [open, { setTrue, setFalse }] = useBoolean(false);
Expand All @@ -30,6 +35,7 @@ export const confirmDialog = () => {
setFalse();
resolve();
};
const { title, description } = options;

return (
<Dialog
Expand All @@ -38,15 +44,15 @@ export const confirmDialog = () => {
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">确认清除剪切板记录</DialogTitle>
<DialogTitle id="alert-dialog-title">{title}</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
清除后无法恢复,请确认是否继续
{description}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>取消</Button>
<Button onClick={handleOK} autoFocus>
<Button onClick={handleOK} color="warning" autoFocus>
确定
</Button>
</DialogActions>
Expand Down

0 comments on commit 7b7552e

Please sign in to comment.