-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
191 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,54 @@ | ||
import { BsDeviceHdd } from "solid-icons/bs"; | ||
import { FiTrash2 } from "solid-icons/fi"; | ||
import { Component, createSignal, onMount } from "solid-js"; | ||
import { DatabaseInfo } from "../../../types"; | ||
import { SiSqlite } from "solid-icons/si"; | ||
import { Component, createResource } from "solid-js"; | ||
import { ClipboardType } from "../../../types/enums"; | ||
import { InvokeCommand } from "../../../types/tauri-invoke"; | ||
import { formatBytes } from "../../../utils/helpers"; | ||
import { invokeCommand } from "../../../utils/tauri"; | ||
import { TextBlock } from "../../elements/text-block"; | ||
|
||
interface SettingsHistoryProps {} | ||
const CLIPBOARD_TYPES: { type: ClipboardType | null; label: string }[] = [ | ||
{ type: null, label: "Clear All" }, | ||
{ type: ClipboardType.Text, label: "Clear Text" }, | ||
{ type: ClipboardType.Html, label: "Clear Html" }, | ||
{ type: ClipboardType.Rtf, label: "Clear Rtf" }, | ||
{ type: ClipboardType.Image, label: "Clear Image" }, | ||
{ type: ClipboardType.File, label: "Clear File" }, | ||
]; | ||
|
||
export const SettingsHistory: Component<SettingsHistoryProps> = ({}) => { | ||
const [databaseInfo, setDatabaseInfo] = createSignal<DatabaseInfo>({ | ||
records: 0, | ||
size: 0, | ||
}); | ||
export const SettingsHistory: Component = () => { | ||
const [databaseInfo, { refetch }] = createResource(() => invokeCommand(InvokeCommand.GetDbInfo)); | ||
|
||
onMount(async () => setDatabaseInfo(await invokeCommand(InvokeCommand.GetDbInfo))); | ||
const handleClear = async (type: ClipboardType | null) => { | ||
await invokeCommand(InvokeCommand.ClearClipboards, { type }); | ||
refetch(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<TextBlock Icon={BsDeviceHdd} title="Local Storage"> | ||
<TextBlock Icon={SiSqlite} title="SQL Database Info"> | ||
<ul class="mx-5 list-disc px-5 pb-5"> | ||
<li>{`${databaseInfo().records} local items (${formatBytes( | ||
databaseInfo().size | ||
)}) are saved on this computer`}</li> | ||
<li> | ||
{`${databaseInfo()?.records} local items (${formatBytes(databaseInfo()?.size)}) are saved on this computer`} | ||
</li> | ||
</ul> | ||
</TextBlock> | ||
|
||
<div class="flex w-full justify-end"> | ||
<button | ||
type="button" | ||
onClick={async () => { | ||
await invokeCommand(InvokeCommand.ClearClipboards); | ||
setDatabaseInfo(await invokeCommand(InvokeCommand.GetDbInfo)); | ||
}} | ||
class="inline-flex items-center space-x-2 rounded bg-zinc-600 px-4 py-2 text-sm font-bold text-white hover:bg-zinc-700" | ||
> | ||
<FiTrash2 /> | ||
<span>Clear...</span> | ||
</button> | ||
</div> | ||
<TextBlock Icon={BsDeviceHdd} title="Storage Actions"> | ||
<div class="flex w-full flex-wrap justify-center gap-2 px-5 pb-5"> | ||
{CLIPBOARD_TYPES.map(({ type, label }) => ( | ||
<button | ||
type="button" | ||
onClick={() => handleClear(type)} | ||
class="inline-flex items-center space-x-2 rounded bg-zinc-600 px-1 py-1 text-xs font-bold text-white hover:bg-zinc-700" | ||
> | ||
<FiTrash2 /> | ||
<span>{label}</span> | ||
</button> | ||
))} | ||
</div> | ||
</TextBlock> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.