From e12aa09a47914e3934e07d8cfdc5f5b7edbfe565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20Osman=20Deli=C5=9Fmen?= Date: Sat, 24 Feb 2024 17:23:47 +0300 Subject: [PATCH] docs: update markdown --- apps/docs/content/index.md | 62 +++++++++++++++++++++++------- apps/playground/src/app/page.tsx | 2 +- packages/library/src/libs/types.ts | 10 +++-- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/apps/docs/content/index.md b/apps/docs/content/index.md index eb58315..e1fd1d8 100644 --- a/apps/docs/content/index.md +++ b/apps/docs/content/index.md @@ -30,27 +30,34 @@ To start using `@postiva/client` in your project, follow these steps: ::code-group -```bash [Npm] +```bash [npm] npm install @postiva/js ``` -```bash [Yarn] +```bash [yarn] yarn add @postiva/js ``` -```bash [Pnpm] +```bash [pnpm] pnpm add @postiva/js ``` :: Next, initialize the Postiva Client in your application by providing your workspace ID and API key: +::code-group -```javascript[libs/postiva.ts] -const { PostivaClient } = require('@postiva/client'); +```javascript[libs/postiva.js] +const { createClient } = require('@postiva/client'); + +const client = createClient('yourWorkspaceId', 'yourApiKey'); +``` +```typescript[libs/postiva.ts] +import { createClient } from '@postiva/client' -const client = new PostivaClient('yourWorkspaceId', 'yourApiKey'); +const client = createClient('yourWorkspaceId', 'yourApiKey'); ``` +:: ## Usage @@ -58,9 +65,10 @@ Here's a simple example to fetch content using the Postiva Client: ### Fetch the contents +::code-group -```javascript[pages/index.tsx] -async function fetchContents() { +```javascript[getContents] +async function getContents() { try { const contents = await client.getContents(); console.log(contents); @@ -69,8 +77,39 @@ async function fetchContents() { } } -fetchContents(); +getContentsWithQuery(); +``` + +```javascript[getContentsWithQuery] +import { GetContentsType } from '@postiva/client' + +async function getContentsWithQuery({ query, type, category }: GetContentsType) { + try { + const contents = await client.getContents({ query, type, category }); + console.log(contents); + } catch (error) { + console.error('Error fetching contents:', error); + } +} + +getContentsWithQuery(); +``` + +```javascript[getContentsWithPagination] +import { GetContentsType } from '@postiva/client' + +async function getContentsWithPagination({ page, size }: IPaginatinoOptions) { + try { + const contents = await client.getContents().pagination({ page, size }) + console.log(contents); + } catch (error) { + console.error('Error fetching contents:', error); + } +} + +getContentsWithPagination(); ``` +:: ### Fetch the content detail @@ -123,11 +162,6 @@ const client = new PostivaClient('yourWorkspaceId'); A secure key used for API authentication. - -```typescript[libs/postiva.ts] -const client = new PostivaClient('yourWorkspaceId', 'apiKey'); -``` - ## Contributing You're welcome to contribute to this module! diff --git a/apps/playground/src/app/page.tsx b/apps/playground/src/app/page.tsx index e9f68c9..3f940d4 100644 --- a/apps/playground/src/app/page.tsx +++ b/apps/playground/src/app/page.tsx @@ -1,7 +1,7 @@ import { postivaClient } from "@/libs/postiva"; export default async function Home() { - const posts = await postivaClient.getContents({query: "test"}).pagination({page: 1, size: 1}) + const posts = await postivaClient.getContents({query: "selam"}).pagination({page: 1, size: 1}) return (
diff --git a/packages/library/src/libs/types.ts b/packages/library/src/libs/types.ts index 22551e7..b2b2e73 100644 --- a/packages/library/src/libs/types.ts +++ b/packages/library/src/libs/types.ts @@ -12,14 +12,16 @@ export interface PaginationResponse { pagination?: IPagination; } +export interface IPaginatinoOptions { + page: number; + size: number; +} + export interface PaginatableResponse { pagination: ({ page, size, - }: { - page: number; - size: number; - }) => Promise>; + }: IPaginatinoOptions) => Promise>; } export type ContentsResponse = Promise & PaginatableResponse;