Skip to content

Commit

Permalink
docs(TwaLoader,useTwa,useVersionAtLeast): docs updated and simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzwan committed Nov 13, 2023
1 parent ea16102 commit 9d4ee68
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 70 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 7 additions & 29 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -596,38 +595,19 @@ 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 <p>Version is at least 6.5</p>;
}
```

---

### 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.

```tsx
import { useVersionAtLeast } from '@altiore/twa';

const isCorrectVersion = useIsVersionAtLeast('6.5');
const isCorrectVersion = useVersionAtLeast('6.9');
if (isCorrectVersion) {
return <p>Version is at least 6.5</p>;
return <p>Version is at least 6.9</p>;
}
```

Expand All @@ -647,7 +627,7 @@ if (isLoading) {
return <p>TWA script still loading</p>;
}
if (isLoaded) {
return <p>TWA script loaded</p>;
return <p>TWA Application ready to use</p>;
}
```

Expand Down Expand Up @@ -828,11 +808,9 @@ Renders its props depends on was TWA loaded or not
import { TwaLoader } from '@altiore/twa';

<TwaLoader
loading={<p>This will be shown while TWA script is loading</p>}
isTWApp={
<p>This will be shown if TWA was loaded in Telegram and available</p>
}
noTWApp={<p>This will be shown is this is not a Telegram environment</p>}
loading={<p>...loading</p>}
isTWApp={<p>I am a Telegram App!</p>}
noTWApp={<p>I am non Telegram App (simple web app)</p>}
/>;
```

Expand Down
4 changes: 2 additions & 2 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
@@ -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",
Expand Down
7 changes: 0 additions & 7 deletions src/TwaLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ export const TwaLoader: FC<IProps> = ({
minVersion ? String(minVersion) : undefined,
);

console.log('TwaLoader state:', {
isCorrectVersion,
isLoading,
isLoaded,
minVersion,
});

if (isLoading) {
return loading;
}
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
24 changes: 0 additions & 24 deletions src/useIsVersionAtLeast.ts

This file was deleted.

3 changes: 1 addition & 2 deletions tests/__snapshots__/package.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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],
Expand Down

0 comments on commit 9d4ee68

Please sign in to comment.