Implementing deep link (#41)
This commit is contained in:
committed by
GitHub
parent
f2115e23c7
commit
b4dbb55548
@@ -1,25 +1,26 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import {ICreatePortal, IPortal, IPortalProp, IPortalToAdd} from './types';
|
||||
import { IPortal, IPortalProp, IPortalToAdd} from './types';
|
||||
|
||||
export async function createNewPortal({
|
||||
name,
|
||||
url,
|
||||
}: ICreatePortal): Promise<IPortal[]> {
|
||||
temporary = false
|
||||
}: IPortal): Promise<IPortal[]> {
|
||||
let portalsStorage: IPortalProp = await getPortals();
|
||||
|
||||
if (portalsStorage === null || portalsStorage === '[]')
|
||||
return await createFromEmptyStorage(name, url);
|
||||
return await createFromEmptyStorage({name, url, temporary});
|
||||
|
||||
portalsStorage = parseString(portalsStorage);
|
||||
|
||||
return await addPortalToStorage({portals: portalsStorage, name, url});
|
||||
return await addPortalToStorage({portals: portalsStorage, name, url, temporary});
|
||||
}
|
||||
|
||||
async function createFromEmptyStorage(name: string, url: string) {
|
||||
async function createFromEmptyStorage({name, url, temporary}:IPortal) {
|
||||
await createStorageEmpty();
|
||||
let portalsStorage = await getPortals();
|
||||
const portalStorage = parseString(portalsStorage!);
|
||||
await addPortalToStorage({portals: portalStorage, name, url});
|
||||
await addPortalToStorage({portals: portalStorage, name, url, temporary});
|
||||
return portalStorage;
|
||||
}
|
||||
|
||||
@@ -39,8 +40,9 @@ async function addPortalToStorage({
|
||||
portals,
|
||||
name,
|
||||
url,
|
||||
temporary
|
||||
}: IPortalToAdd): Promise<IPortal[]> {
|
||||
portals.push({name, url});
|
||||
portals.push({name, url, temporary});
|
||||
await AsyncStorage.setItem('portal', JSON.stringify(portals));
|
||||
return portals;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
export type ICreatePortal = {
|
||||
name: string;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export type IPortal = {
|
||||
name: string;
|
||||
url: string;
|
||||
temporary: boolean
|
||||
};
|
||||
|
||||
export type IPortalToAdd = {
|
||||
portals: Array<IPortal>;
|
||||
name: string;
|
||||
url: string;
|
||||
temporary: boolean;
|
||||
};
|
||||
|
||||
export type IPortalProp = string | null | IPortal[];
|
||||
|
||||
Reference in New Issue
Block a user