Skip to content

Commit

Permalink
Add jsdoc to mobile app
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Sep 24, 2023
1 parent a393ade commit 1301c86
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 24 deletions.
1 change: 0 additions & 1 deletion mobile/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 47 additions & 16 deletions mobile/common/AsyncStorage.ts
Original file line number Diff line number Diff line change
@@ -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<T>(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<T>(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)
}
}
5 changes: 5 additions & 0 deletions mobile/common/AxiosHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions mobile/common/ToastHelper.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
135 changes: 128 additions & 7 deletions mobile/config/env.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
BC_APP_TYPE,
BC_API_HOST,
BC_DEFAULT_LANGUAGE,
BC_PAGE_SIZE,
Expand All @@ -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

0 comments on commit 1301c86

Please sign in to comment.