Skip to content

Commit

Permalink
feat: add shortcut for text save (close alist-org/alist#5396)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Oct 22, 2023
1 parent 04d98e9 commit ab6701c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -55,6 +55,7 @@
"@monaco-editor/loader": "^1.3.2",
"@motionone/solid": "^10.14.1",
"@solid-primitives/i18n": "^1.1.0",
"@solid-primitives/keyboard": "^1.2.5",
"@solid-primitives/storage": "^1.3.1",
"@stitches/core": "^1.2.8",
"aplayer": "^1.10.1",
Expand Down
40 changes: 40 additions & 0 deletions pnpm-lock.yaml

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

24 changes: 11 additions & 13 deletions src/pages/home/previews/text-editor.tsx
Expand Up @@ -6,6 +6,7 @@ import { useFetch, useFetchText, useParseText, useRouter, useT } from "~/hooks"
import { objStore, userCan } from "~/store"
import { PEmptyResp } from "~/types"
import { handleResp, notify, r } from "~/utils"
import { createShortcut } from "@solid-primitives/keyboard"

function Editor(props: { data?: string | ArrayBuffer; contentType?: string }) {
const { colorMode } = useColorMode()
Expand Down Expand Up @@ -33,6 +34,15 @@ function Editor(props: { data?: string | ArrayBuffer; contentType?: string }) {
}),
)

async function onSave() {
const resp = await save()
handleResp(resp, () => {
notify.success(t("global.save_success"))
})
}

createShortcut(["Control", "S"], onSave)

return (
<VStack w="$full" alignItems="start" spacing="$2" pos="relative">
<Show when={!isString}>
Expand All @@ -47,19 +57,7 @@ function Editor(props: { data?: string | ArrayBuffer; contentType?: string }) {
}}
/>
<Show when={userCan("write") || objStore.write}>
<Button
loading={loading()}
onClick={async () => {
// if (!value()) {
// notify.success(t("global.save_success"))
// return
// }
const resp = await save()
handleResp(resp, () => {
notify.success(t("global.save_success"))
})
}}
>
<Button loading={loading()} onClick={onSave}>
{t("global.save")}
</Button>
</Show>
Expand Down

0 comments on commit ab6701c

Please sign in to comment.