From 1301c86796e01fd6b7901be49b20d01d83eb2ec9 Mon Sep 17 00:00:00 2001 From: aelassas Date: Sun, 24 Sep 2023 20:15:44 +0100 Subject: [PATCH] Add jsdoc to mobile app --- mobile/.env.example | 1 - mobile/common/AsyncStorage.ts | 63 ++++++++++++---- mobile/common/AxiosHelper.ts | 5 ++ mobile/common/ToastHelper.ts | 11 +++ mobile/config/env.config.ts | 135 ++++++++++++++++++++++++++++++++-- 5 files changed, 191 insertions(+), 24 deletions(-) diff --git a/mobile/.env.example b/mobile/.env.example index 508d048b6..cb17e1316 100644 --- a/mobile/.env.example +++ b/mobile/.env.example @@ -9,5 +9,4 @@ BC_COMPANY_IMAGE_WIDTH=60 BC_COMPANY_IMAGE_HEIGHT=30 BC_CAR_IMAGE_WIDTH=300 BC_CAR_IMAGE_HEIGHT=200 -BC_APP_TYPE=frontend BC_MINIMUM_AGE=21 diff --git a/mobile/common/AsyncStorage.ts b/mobile/common/AsyncStorage.ts index be002766e..d13bc1397 100644 --- a/mobile/common/AsyncStorage.ts +++ b/mobile/common/AsyncStorage.ts @@ -1,57 +1,88 @@ import ReactAsyncStorage from '@react-native-async-storage/async-storage' -import Toast from 'react-native-root-toast' -import i18n from '../lang/i18n' - -export const error = (err: unknown) => { - if (err) { - console.log(err) - } - Toast.show(i18n.t('GENERIC_ERROR'), { - duration: Toast.durations.LONG, - }) -} +import * as ToastHelper from './ToastHelper' +/** + * Store a string in async-storage. + * + * @async + * @param {string} key + * @param {string} value + * @returns {void} + */ export const storeString = async (key: string, value: string) => { try { await ReactAsyncStorage.setItem(key, value) } catch (err) { - error(err) + ToastHelper.error(err) } } +/** + * Get a string by key from async-storage. + * + * @async + * @param {string} key + * @returns {unknown} + */ export const getString = async (key: string) => { try { const value = await ReactAsyncStorage.getItem(key) return value } catch (err) { - error(err) + ToastHelper.error(err) } } +/** + * Store an object in async-storage. + * + * @export + * @async + * @template T + * @param {string} key + * @param {T} value + * @returns {void} + */ export async function storeObject(key: string, value: T) { try { const jsonValue = JSON.stringify(value) await ReactAsyncStorage.setItem(key, jsonValue) } catch (err) { - error(err) + ToastHelper.error(err) } } +/** + * Get an object by key from async-storage. + * + * @export + * @async + * @template T + * @param {string} key + * @returns {T|null} + */ export async function getObject(key: string) { try { const value = await ReactAsyncStorage.getItem(key) const jsonValue = value != null ? JSON.parse(value) as T : null return jsonValue } catch (err) { - error(err) + ToastHelper.error(err) return null } } +/** + * Remove an item by key from async-storage. + * + * @async + * @param {string} key + * @returns {void} + */ export const removeItem = async (key: string) => { try { await ReactAsyncStorage.removeItem(key) } catch (err) { - error(err) + ToastHelper.error(err) } } diff --git a/mobile/common/AxiosHelper.ts b/mobile/common/AxiosHelper.ts index 2b34b8847..e1095757b 100644 --- a/mobile/common/AxiosHelper.ts +++ b/mobile/common/AxiosHelper.ts @@ -2,6 +2,11 @@ import { AxiosStatic } from 'axios' import * as Env from '../config/env.config' import axiosRetry from 'axios-retry' +/** + * Initialize axios-retry. + * + * @param {AxiosStatic} axios + */ export const init = (axios: AxiosStatic) => { axiosRetry(axios, { retries: Env.AXIOS_RETRIES, // number of retries diff --git a/mobile/common/ToastHelper.ts b/mobile/common/ToastHelper.ts index 92d249fe7..6d8e7e678 100644 --- a/mobile/common/ToastHelper.ts +++ b/mobile/common/ToastHelper.ts @@ -1,12 +1,23 @@ import Toast from 'react-native-root-toast' import i18n from '../lang/i18n' +/** + * Toast a message. + * + * @param {string} message + */ export const toast = (message: string) => { Toast.show(message, { duration: Toast.durations.LONG, }) } +/** + * Toast an error message. + * + * @param {?unknown} [err] + * @param {boolean} [__toast__=true] + */ export const error = (err?: unknown, __toast__ = true) => { if (err) { console.log(err) diff --git a/mobile/config/env.config.ts b/mobile/config/env.config.ts index 92602a192..3aad00368 100644 --- a/mobile/config/env.config.ts +++ b/mobile/config/env.config.ts @@ -1,5 +1,4 @@ import { - BC_APP_TYPE, BC_API_HOST, BC_DEFAULT_LANGUAGE, BC_PAGE_SIZE, @@ -14,27 +13,149 @@ import { BC_MINIMUM_AGE, } from '@env' -const EN = 'en' // English ISO 639-1 language code -const FR = 'fr' // French ISO 639-1 language code +/** + * English ISO 639-1 language code. + * + * @type {'en'} + */ +const EN = 'en' -export const APP_TYPE: string = BC_APP_TYPE || 'frontend' +/** + * French ISO 639-1 language code. + * + * @type {'fr'} + */ +const FR = 'fr' + +/** + * Application type. + * + * @type {string} + */ +export const APP_TYPE: string = 'frontend' + +/** + * API host. + * + * @type {string} + */ export const API_HOST: string = BC_API_HOST + +/** + * Number of maximum axios retries. + * + * @type {number} + */ export const AXIOS_RETRIES: number = 3 + +/** + * Axios retries interval in milliseconds. + * + * @type {number} + */ export const AXIOS_RETRIES_INTERVAL: number = 500 // in milliseconds + +/** + * Languages. + * + * @type {string[]} + */ export const LANGUAGES: string[] = [EN, FR] + +/** + * Default language. Default is English. + * + * @type {string} + */ export const DEFAULT_LANGUAGE: string = BC_DEFAULT_LANGUAGE || EN + +/** + * Languages. + * + * @type {{ EN: 'en', FR: 'fr' }} + */ export const LANGUAGE: { EN: 'en', FR: 'fr' } = { EN, FR } -export const AXIOS_TIMEOUT: number = 5000 // in milliseconds + +/** + * Axios timeout in milliseconds. + * + * @type {number} + */ +export const AXIOS_TIMEOUT: number = 5000 + +/** + * Page size. Default is 20. + * + * @type {number} + */ export const PAGE_SIZE: number = Number.parseInt(BC_PAGE_SIZE) || 20 + +/** + * Cars page size. Default is 8. + * + * @type {number} + */ export const CARS_PAGE_SIZE: number = Number.parseInt(BC_CARS_PAGE_SIZE) || 8 + +/** + * Bookings page size. Default is 8. + * + * @type {number} + */ export const BOOKINGS_PAGE_SIZE: number = Number.parseInt(BC_BOOKINGS_PAGE_SIZE) || 8 + +/** + * User images CDN. + * + * @type {string} + */ export const CDN_USERS: string = BC_CDN_USERS + +/** + * Car images CDN. + * + * @type {string} + */ export const CDN_CARS: string = BC_CDN_CARS + +/** + * Page offset. + * + * @type {number} + */ export const PAGE_OFFSET: number = 200 + +/** + * Supplier image width. Default is 60. + * + * @type {number} + */ export const COMPANY_IMAGE_WIDTH: number = Number.parseInt(BC_COMPANY_IMAGE_WIDTH) || 60 + +/** + * Supplier image height. Default is 30. + * + * @type {number} + */ export const COMPANY_IMAGE_HEIGHT: number = Number.parseInt(BC_COMPANY_IMAGE_HEIGHT) || 30 + +/** + * Car image width. Default is 300. + * + * @type {number} + */ export const CAR_IMAGE_WIDTH: number = Number.parseInt(BC_CAR_IMAGE_WIDTH) || 300 + +/** + * Car image height. Default is 200. + * + * @type {number} + */ export const CAR_IMAGE_HEIGHT: number = Number.parseInt(BC_CAR_IMAGE_HEIGHT) || 200 -export const CAR_OPTION_IMAGE_HEIGHT: number = 85 -export const SELECTED_CAR_OPTION_IMAGE_HEIGHT: number = 30 + +/** + * Minimum age. Default is 21. + * + * @type {number} + */ export const MINIMUM_AGE: number = Number.parseInt(BC_MINIMUM_AGE) || 21