diff --git a/package-lock.json b/package-lock.json index ad4ca56d..68e1d59b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "@emotion/css": "^11.11.2", "@mdi/font": "^5.9.55", "@supabase/supabase-js": "^2.38.0", - "@twa-dev/sdk": "^6.9.0", + "@twa-dev/sdk": "^7.0.0", "autosize": "^6.0.1", "colord": "^2.9.3", "framer-motion": "^10.16.4", @@ -1380,20 +1380,20 @@ } }, "node_modules/@twa-dev/sdk": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@twa-dev/sdk/-/sdk-6.9.0.tgz", - "integrity": "sha512-HP5LFRoSVqHXoRrjBqTQqTFy1R7TORmykqOucRH8C1ZGgO76u2ezthCFqxk5ERW5WXOm2bVkQf1Hbv9tLaEszg==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@twa-dev/sdk/-/sdk-7.0.0.tgz", + "integrity": "sha512-OZvqGGrdrgE0xU/IGjvsGKKouia5bTu6rA/BOOU6pJYLu776nQJs/HNFl7lwW16RONf1vvPqeV8XximsuzZ9Iw==", "dependencies": { - "@twa-dev/types": "^6.9.0" + "@twa-dev/types": "^7.0.0" }, "peerDependencies": { "react": ">=16.0.0" } }, "node_modules/@twa-dev/types": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@twa-dev/types/-/types-6.9.0.tgz", - "integrity": "sha512-hBkIuJgVtkLAPPhKsNfgyBpgS+15spzUScy5jgpfPJPqXPaaUVDTaWHbeEUU+lUgHmryeQjWyz+UjS7987Pyaw==" + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@twa-dev/types/-/types-7.0.0.tgz", + "integrity": "sha512-LBnMklxORuXd/ypv9gFKcQVNJkCktkeuU+2V6B5Ww7dcxDCoYBAKkNnIwEQ3cShq+cxTi96jC/CqWhgDMQ7AXQ==" }, "node_modules/@types/autosize": { "version": "4.0.3", diff --git a/package.json b/package.json index b572c996..aac0bd75 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@emotion/css": "^11.11.2", "@mdi/font": "^5.9.55", "@supabase/supabase-js": "^2.38.0", - "@twa-dev/sdk": "^6.9.0", + "@twa-dev/sdk": "^7.0.0", "autosize": "^6.0.1", "colord": "^2.9.3", "framer-motion": "^10.16.4", diff --git a/src/lib/telegram/use-settings-button.ts b/src/lib/telegram/use-settings-button.ts new file mode 100644 index 00000000..948be159 --- /dev/null +++ b/src/lib/telegram/use-settings-button.ts @@ -0,0 +1,18 @@ +import WebApp from "@twa-dev/sdk"; +import { useMount } from "../react/use-mount.ts"; + +export const useSettingsButton = (fn: () => void) => { + useMount(() => { + if (!WebApp.isVersionAtLeast("7.0")) { + return; + } + + WebApp.SettingsButton.show(); + WebApp.SettingsButton.onClick(fn); + + return () => { + WebApp.SettingsButton.hide(); + WebApp.SettingsButton.offClick(fn); + }; + }); +}; diff --git a/src/screens/app.tsx b/src/screens/app.tsx index a72f382b..c649016a 100644 --- a/src/screens/app.tsx +++ b/src/screens/app.tsx @@ -25,10 +25,15 @@ import { ShareDeckScreen } from "./share-deck/share-deck-screen.tsx"; import { ShareDeckStoreProvider } from "./share-deck/store/share-deck-store-context.tsx"; import { FolderFormStoreProvider } from "./folder-form/store/folder-form-store-context.tsx"; import { FolderScreen } from "./folder-review/folder-screen.tsx"; +import { useSettingsButton } from "../lib/telegram/use-settings-button.ts"; export const App = observer(() => { useRestoreFullScreenExpand(); + useSettingsButton(() => { + screenStore.go({ type: "userSettings" }); + }); + if (deckListStore.isFullScreenLoaderVisible) { return ; }