Skip to content

Commit

Permalink
Support Telegram API 7.0 settings button
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Jan 10, 2024
1 parent 59e8eb8 commit cca50a9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions src/lib/telegram/use-settings-button.ts
Original file line number Diff line number Diff line change
@@ -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);
};
});
};
5 changes: 5 additions & 0 deletions src/screens/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <FullScreenLoader />;
}
Expand Down

0 comments on commit cca50a9

Please sign in to comment.