diff --git a/README.md b/README.md index 386c56c..99a0d8b 100644 --- a/README.md +++ b/README.md @@ -84,12 +84,10 @@ const Content = () => { This hook provides `CloudStorage` object as Promise functions - [useInitData](./docs/README.md#useinitdata) - This hook provides `InitDataUnsafe` and `InitData` object -- [useIsVersionAtLeast](./docs/README.md#useisversionatleast) - - This hook provides `isVersionAtLeast` function - [useVersionAtLeast](./docs/README.md#useversionatleast) - - This hook provides `isVersionAtLeast` result which is boolean + This hook provides `isVersionAtLeast` function result which is always boolean - [useTwa](./docs/README.md#usetwa) - - This hook provides boolean values indicates was TWA script loaded or not + This hook provides boolean values indicating whether the Telegram Web App is ready for use (loaded) or not (still loading). - [useWebApp](./docs/README.md#usewebapp) - This hook just provides native `WebApp` object diff --git a/docs/README.md b/docs/README.md index 5309ffb..9f6840f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -44,7 +44,6 @@ - [useExpand](README.md#useexpand) - [useHapticFeedback](README.md#usehapticfeedback) - [useInitData](README.md#useinitdata) -- [useIsVersionAtLeast](README.md#useIsVersionAtLeast) - [useReadTextFromClipboard](README.md#usereadtextfromclipboard) - [useScanQrPopup](README.md#usescanqrpopup) - [useShowPopup](README.md#useshowpopup) @@ -596,28 +595,9 @@ readonly [[`InitDataUnsafe`](README.md#initdataunsafe), `string`] --- -### useIsVersionAtLeast - -▸ **useIsVersionAtLeast**(): (version: string | number) => boolean - -This hook provides `isVersionAtLeast` function -You have to look original description in [telegram!WebApp](https://core.telegram.org/bots/webapps#initializing-mini-apps), because hook just return this. - -```tsx -import { useIsVersionAtLeast } from '@altiore/twa'; - -const isVersionAtLeast = useIsVersionAtLeast(); - -if (isVersionAtLeast('6.5')) { - return

Version is at least 6.5

; -} -``` - ---- - ### useVersionAtLeast -▸ **useVersionAtLeast**(): readonly boolean +▸ **useVersionAtLeast**(version?: string | number): readonly boolean This hook provides `isVersionAtLeast` function result You have to look original description in [telegram!WebApp](https://core.telegram.org/bots/webapps#initializing-mini-apps), because hook just return this. @@ -625,9 +605,9 @@ You have to look original description in [telegram!WebApp](https://core.telegram ```tsx import { useVersionAtLeast } from '@altiore/twa'; -const isCorrectVersion = useIsVersionAtLeast('6.5'); +const isCorrectVersion = useVersionAtLeast('6.9'); if (isCorrectVersion) { - return

Version is at least 6.5

; + return

Version is at least 6.9

; } ``` @@ -647,7 +627,7 @@ if (isLoading) { return

TWA script still loading

; } if (isLoaded) { - return

TWA script loaded

; + return

TWA Application ready to use

; } ``` @@ -828,11 +808,9 @@ Renders its props depends on was TWA loaded or not import { TwaLoader } from '@altiore/twa'; This will be shown while TWA script is loading

} - isTWApp={ -

This will be shown if TWA was loaded in Telegram and available

- } - noTWApp={

This will be shown is this is not a Telegram environment

} + loading={

...loading

} + isTWApp={

I am a Telegram App!

} + noTWApp={

I am non Telegram App (simple web app)

} />; ``` diff --git a/package-lock.json b/package-lock.json index b9e37c3..c171218 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@altiore/twa", - "version": "1.2.15", + "version": "1.2.16", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@altiore/twa", - "version": "1.2.15", + "version": "1.2.16", "license": "MIT", "devDependencies": { "@changesets/cli": "2.25.2", diff --git a/package.json b/package.json index efb1014..cca0c3a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@altiore/twa", - "version": "1.2.15", + "version": "1.2.16", "description": "React components for Telegram WebApp", "source": "./src/index.ts", "type": "module", diff --git a/src/TwaLoader.tsx b/src/TwaLoader.tsx index e8cb98d..cdf0cb3 100644 --- a/src/TwaLoader.tsx +++ b/src/TwaLoader.tsx @@ -31,13 +31,6 @@ export const TwaLoader: FC = ({ minVersion ? String(minVersion) : undefined, ); - console.log('TwaLoader state:', { - isCorrectVersion, - isLoading, - isLoaded, - minVersion, - }); - if (isLoading) { return loading; } diff --git a/src/index.ts b/src/index.ts index 32a8cb5..9f2a243 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,7 +55,6 @@ export { } from './useInitData'; export type { Options } from './core'; export { default as useWebApp } from './useWebApp'; -export { useIsVersionAtLeast } from './useIsVersionAtLeast'; export { useVersionAtLeast } from './useVersionAtLeast'; export { useTwa } from './useTwa'; export { TwaLoader } from './TwaLoader'; diff --git a/src/useIsVersionAtLeast.ts b/src/useIsVersionAtLeast.ts deleted file mode 100644 index cafc093..0000000 --- a/src/useIsVersionAtLeast.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { useWebApp } from './core'; -import { useCallback, useMemo } from 'react'; - -/** - * A hook that shows version minimum check - */ -export type VersionAtLeastFunction = (version: string | number) => boolean; - -/** - * The hook provided isVersionAtLeast function of the type {@link VersionAtLeastFunction} - * @group Hooks - */ -export const useIsVersionAtLeast = (): VersionAtLeastFunction => { - const WebApp = useWebApp(); - - const _isVersionAtLeast = useMemo(() => { - return WebApp?.isVersionAtLeast; - }, [WebApp]); - - return useCallback( - (version: string | number) => _isVersionAtLeast?.(version) ?? false, - [_isVersionAtLeast], - ); -}; diff --git a/tests/__snapshots__/package.test.ts.snap b/tests/__snapshots__/package.test.ts.snap index bf1eff0..58b9bf3 100644 --- a/tests/__snapshots__/package.test.ts.snap +++ b/tests/__snapshots__/package.test.ts.snap @@ -20,6 +20,7 @@ exports[`Package /lib should have correct /lib structure 1`] = ` ], "/core/useSmoothButtonsTransition.d.ts", "/core/useWebApp.d.ts", + "/core/utils.d.ts", ], "/index.d.ts", "/react-telegram-web-app.cjs", @@ -30,7 +31,6 @@ exports[`Package /lib should have correct /lib structure 1`] = ` "/useExpand.d.ts", "/useHapticFeedback.d.ts", "/useInitData.d.ts", - "/useIsVersionAtLeast.d.ts", "/useReadTextFromClipboard.d.ts", "/useScanQrPopup.d.ts", "/useShowPopup.d.ts", @@ -52,7 +52,6 @@ exports[`Package /lib should have exports from modules 1`] = ` "useExpand": [Function], "useHapticFeedback": [Function], "useInitData": [Function], - "useIsVersionAtLeast": [Function], "useReadTextFromClipboard": [Function], "useScanQrPopup": [Function], "useShowPopup": [Function],