feat(smart-app): implement complete mobile app MVP

- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
This commit is contained in:
Eric FELIXINE
2026-06-01 18:00:35 -04:00
parent 08ca495bde
commit e30ae8ed09
35578 changed files with 3703534 additions and 43 deletions

View File

@@ -0,0 +1,55 @@
import { nanoid } from 'nanoid/non-secure';
/**
* Base router object that can be used when writing custom routers.
* This provides few helper methods to handle common actions such as `RESET`.
*/
const BaseRouter = {
getStateForAction(state, action) {
switch (action.type) {
case 'SET_PARAMS':
{
const index = action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
if (index === -1) {
return null;
}
return {
...state,
routes: state.routes.map((r, i) => i === index ? {
...r,
params: {
...r.params,
...action.payload.params
}
} : r)
};
}
case 'RESET':
{
const nextState = action.payload;
if (nextState.routes.length === 0 || nextState.routes.some(route => !state.routeNames.includes(route.name))) {
return null;
}
if (nextState.stale === false) {
if (state.routeNames.length !== nextState.routeNames.length || nextState.routeNames.some(name => !state.routeNames.includes(name))) {
return null;
}
return {
...nextState,
routes: nextState.routes.map(route => route.key ? route : {
...route,
key: `${route.name}-${nanoid()}`
})
};
}
return nextState;
}
default:
return null;
}
},
shouldActionChangeFocus(action) {
return action.type === 'NAVIGATE';
}
};
export default BaseRouter;
//# sourceMappingURL=BaseRouter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["nanoid","BaseRouter","getStateForAction","state","action","type","index","source","routes","findIndex","r","key","map","i","params","payload","nextState","length","some","route","routeNames","includes","name","stale","shouldActionChangeFocus"],"sourceRoot":"../../src","sources":["BaseRouter.tsx"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAQ1C;AACA;AACA;AACA;AACA,MAAMC,UAAU,GAAG;EACjBC,iBAAiB,CACfC,KAAY,EACZC,MAA8B,EACM;IACpC,QAAQA,MAAM,CAACC,IAAI;MACjB,KAAK,YAAY;QAAE;UACjB,MAAMC,KAAK,GAAGF,MAAM,CAACG,MAAM,GACvBJ,KAAK,CAACK,MAAM,CAACC,SAAS,CAAEC,CAAC,IAAKA,CAAC,CAACC,GAAG,KAAKP,MAAM,CAACG,MAAM,CAAC,GACtDJ,KAAK,CAACG,KAAK;UAEf,IAAIA,KAAK,KAAK,CAAC,CAAC,EAAE;YAChB,OAAO,IAAI;UACb;UAEA,OAAO;YACL,GAAGH,KAAK;YACRK,MAAM,EAAEL,KAAK,CAACK,MAAM,CAACI,GAAG,CAAC,CAACF,CAAC,EAAEG,CAAC,KAC5BA,CAAC,KAAKP,KAAK,GACP;cAAE,GAAGI,CAAC;cAAEI,MAAM,EAAE;gBAAE,GAAGJ,CAAC,CAACI,MAAM;gBAAE,GAAGV,MAAM,CAACW,OAAO,CAACD;cAAO;YAAE,CAAC,GAC3DJ,CAAC;UAET,CAAC;QACH;MAEA,KAAK,OAAO;QAAE;UACZ,MAAMM,SAAS,GAAGZ,MAAM,CAACW,OAAsC;UAE/D,IACEC,SAAS,CAACR,MAAM,CAACS,MAAM,KAAK,CAAC,IAC7BD,SAAS,CAACR,MAAM,CAACU,IAAI,CAClBC,KAAuB,IAAK,CAAChB,KAAK,CAACiB,UAAU,CAACC,QAAQ,CAACF,KAAK,CAACG,IAAI,CAAC,CACpE,EACD;YACA,OAAO,IAAI;UACb;UAEA,IAAIN,SAAS,CAACO,KAAK,KAAK,KAAK,EAAE;YAC7B,IACEpB,KAAK,CAACiB,UAAU,CAACH,MAAM,KAAKD,SAAS,CAACI,UAAU,CAACH,MAAM,IACvDD,SAAS,CAACI,UAAU,CAACF,IAAI,CACtBI,IAAI,IAAK,CAACnB,KAAK,CAACiB,UAAU,CAACC,QAAQ,CAACC,IAAI,CAAC,CAC3C,EACD;cACA,OAAO,IAAI;YACb;YAEA,OAAO;cACL,GAAGN,SAAS;cACZR,MAAM,EAAEQ,SAAS,CAACR,MAAM,CAACI,GAAG,CAAEO,KAAK,IACjCA,KAAK,CAACR,GAAG,GAAGQ,KAAK,GAAG;gBAAE,GAAGA,KAAK;gBAAER,GAAG,EAAG,GAAEQ,KAAK,CAACG,IAAK,IAAGtB,MAAM,EAAG;cAAE,CAAC;YAEtE,CAAC;UACH;UAEA,OAAOgB,SAAS;QAClB;MAEA;QACE,OAAO,IAAI;IAAC;EAElB,CAAC;EAEDQ,uBAAuB,CAACpB,MAA8B,EAAE;IACtD,OAAOA,MAAM,CAACC,IAAI,KAAK,UAAU;EACnC;AACF,CAAC;AAED,eAAeJ,UAAU"}

View File

@@ -0,0 +1,41 @@
export function goBack() {
return {
type: 'GO_BACK'
};
}
// eslint-disable-next-line no-redeclare
export function navigate() {
if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') {
return {
type: 'NAVIGATE',
payload: {
name: arguments.length <= 0 ? undefined : arguments[0],
params: arguments.length <= 1 ? undefined : arguments[1]
}
};
} else {
const payload = (arguments.length <= 0 ? undefined : arguments[0]) || {};
if (!payload.hasOwnProperty('key') && !payload.hasOwnProperty('name')) {
throw new Error('You need to specify name or key when calling navigate with an object as the argument. See https://reactnavigation.org/docs/navigation-actions#navigate for usage.');
}
return {
type: 'NAVIGATE',
payload
};
}
}
export function reset(state) {
return {
type: 'RESET',
payload: state
};
}
export function setParams(params) {
return {
type: 'SET_PARAMS',
payload: {
params
}
};
}
//# sourceMappingURL=CommonActions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["goBack","type","navigate","payload","name","params","hasOwnProperty","Error","reset","state","setParams"],"sourceRoot":"../../src","sources":["CommonActions.tsx"],"mappings":"AAgDA,OAAO,SAASA,MAAM,GAAW;EAC/B,OAAO;IAAEC,IAAI,EAAE;EAAU,CAAC;AAC5B;AAeA;AACA,OAAO,SAASC,QAAQ,GAAuB;EAC7C,IAAI,yDAAc,KAAK,QAAQ,EAAE;IAC/B,OAAO;MAAED,IAAI,EAAE,UAAU;MAAEE,OAAO,EAAE;QAAEC,IAAI,kDAAS;QAAEC,MAAM;MAAU;IAAE,CAAC;EAC1E,CAAC,MAAM;IACL,MAAMF,OAAO,GAAG,sDAAW,CAAC,CAAC;IAE7B,IAAI,CAACA,OAAO,CAACG,cAAc,CAAC,KAAK,CAAC,IAAI,CAACH,OAAO,CAACG,cAAc,CAAC,MAAM,CAAC,EAAE;MACrE,MAAM,IAAIC,KAAK,CACb,mKAAmK,CACpK;IACH;IAEA,OAAO;MAAEN,IAAI,EAAE,UAAU;MAAEE;IAAQ,CAAC;EACtC;AACF;AAEA,OAAO,SAASK,KAAK,CAACC,KAA6B,EAAU;EAC3D,OAAO;IAAER,IAAI,EAAE,OAAO;IAAEE,OAAO,EAAEM;EAAM,CAAC;AAC1C;AAEA,OAAO,SAASC,SAAS,CAACL,MAAc,EAAU;EAChD,OAAO;IAAEJ,IAAI,EAAE,YAAY;IAAEE,OAAO,EAAE;MAAEE;IAAO;EAAE,CAAC;AACpD"}

View File

@@ -0,0 +1,148 @@
import { nanoid } from 'nanoid/non-secure';
import TabRouter, { TabActions } from './TabRouter';
export const DrawerActions = {
...TabActions,
openDrawer() {
return {
type: 'OPEN_DRAWER'
};
},
closeDrawer() {
return {
type: 'CLOSE_DRAWER'
};
},
toggleDrawer() {
return {
type: 'TOGGLE_DRAWER'
};
}
};
export default function DrawerRouter(_ref) {
let {
defaultStatus = 'closed',
...rest
} = _ref;
const router = TabRouter(rest);
const isDrawerInHistory = state => {
var _state$history;
return Boolean((_state$history = state.history) === null || _state$history === void 0 ? void 0 : _state$history.some(it => it.type === 'drawer'));
};
const addDrawerToHistory = state => {
if (isDrawerInHistory(state)) {
return state;
}
return {
...state,
history: [...state.history, {
type: 'drawer',
status: defaultStatus === 'open' ? 'closed' : 'open'
}]
};
};
const removeDrawerFromHistory = state => {
if (!isDrawerInHistory(state)) {
return state;
}
return {
...state,
history: state.history.filter(it => it.type !== 'drawer')
};
};
const openDrawer = state => {
if (defaultStatus === 'open') {
return removeDrawerFromHistory(state);
}
return addDrawerToHistory(state);
};
const closeDrawer = state => {
if (defaultStatus === 'open') {
return addDrawerToHistory(state);
}
return removeDrawerFromHistory(state);
};
return {
...router,
type: 'drawer',
getInitialState(_ref2) {
let {
routeNames,
routeParamList,
routeGetIdList
} = _ref2;
const state = router.getInitialState({
routeNames,
routeParamList,
routeGetIdList
});
return {
...state,
default: defaultStatus,
stale: false,
type: 'drawer',
key: `drawer-${nanoid()}`
};
},
getRehydratedState(partialState, _ref3) {
let {
routeNames,
routeParamList,
routeGetIdList
} = _ref3;
if (partialState.stale === false) {
return partialState;
}
let state = router.getRehydratedState(partialState, {
routeNames,
routeParamList,
routeGetIdList
});
if (isDrawerInHistory(partialState)) {
// Re-sync the drawer entry in history to correct it if it was wrong
state = removeDrawerFromHistory(state);
state = addDrawerToHistory(state);
}
return {
...state,
default: defaultStatus,
type: 'drawer',
key: `drawer-${nanoid()}`
};
},
getStateForRouteFocus(state, key) {
const result = router.getStateForRouteFocus(state, key);
return closeDrawer(result);
},
getStateForAction(state, action, options) {
switch (action.type) {
case 'OPEN_DRAWER':
return openDrawer(state);
case 'CLOSE_DRAWER':
return closeDrawer(state);
case 'TOGGLE_DRAWER':
if (isDrawerInHistory(state)) {
return removeDrawerFromHistory(state);
}
return addDrawerToHistory(state);
case 'JUMP_TO':
case 'NAVIGATE':
{
const result = router.getStateForAction(state, action, options);
if (result != null && result.index !== state.index) {
return closeDrawer(result);
}
return result;
}
case 'GO_BACK':
if (isDrawerInHistory(state)) {
return removeDrawerFromHistory(state);
}
return router.getStateForAction(state, action, options);
default:
return router.getStateForAction(state, action, options);
}
},
actionCreators: DrawerActions
};
}
//# sourceMappingURL=DrawerRouter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["nanoid","TabRouter","TabActions","DrawerActions","openDrawer","type","closeDrawer","toggleDrawer","DrawerRouter","defaultStatus","rest","router","isDrawerInHistory","state","Boolean","history","some","it","addDrawerToHistory","status","removeDrawerFromHistory","filter","getInitialState","routeNames","routeParamList","routeGetIdList","default","stale","key","getRehydratedState","partialState","getStateForRouteFocus","result","getStateForAction","action","options","index","actionCreators"],"sourceRoot":"../../src","sources":["DrawerRouter.tsx"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAE1C,OAAOC,SAAS,IAEdC,UAAU,QAIL,aAAa;AA4DpB,OAAO,MAAMC,aAAa,GAAG;EAC3B,GAAGD,UAAU;EACbE,UAAU,GAAqB;IAC7B,OAAO;MAAEC,IAAI,EAAE;IAAc,CAAC;EAChC,CAAC;EACDC,WAAW,GAAqB;IAC9B,OAAO;MAAED,IAAI,EAAE;IAAe,CAAC;EACjC,CAAC;EACDE,YAAY,GAAqB;IAC/B,OAAO;MAAEF,IAAI,EAAE;IAAgB,CAAC;EAClC;AACF,CAAC;AAED,eAAe,SAASG,YAAY,OAMlC;EAAA,IANmC;IACnCC,aAAa,GAAG,QAAQ;IACxB,GAAGC;EACgB,CAAC;EAIpB,MAAMC,MAAM,GAAGV,SAAS,CAACS,IAAI,CAG5B;EAED,MAAME,iBAAiB,GACrBC,KAEsD;IAAA;IAAA,OACnDC,OAAO,mBAACD,KAAK,CAACE,OAAO,mDAAb,eAAeC,IAAI,CAAEC,EAAE,IAAKA,EAAE,CAACZ,IAAI,KAAK,QAAQ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kBAAkB,CAACL,KAAK,CAAC;QAElC,KAAK,SAAS;QACd,KAAK,UAAU;UAAE;YACf,MAAMmB,MAAM,GAAGrB,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;YAE/D,IAAIH,MAAM,IAAI,IAAI,IAAIA,MAAM,CAACI,KAAK,KAAKvB,KAAK,CAACuB,KAAK,EAAE;cAClD,OAAO9B,WAAW,CAAC0B,MAAM,CAAyC;YACpE;YAEA,OAAOA,MAAM;UACf;QAEA,KAAK,SAAS;UACZ,IAAIpB,iBAAiB,CAACC,KAAK,CAAC,EAAE;YAC5B,OAAOO,uBAAuB,CAACP,KAAK,CAAC;UACvC;UAEA,OAAOF,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;QAEzD;UACE,OAAOxB,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;MAAC;IAE9D,CAAC;IAEDE,cAAc,EAAElC;EAClB,CAAC;AACH"}

View File

@@ -0,0 +1,306 @@
import { nanoid } from 'nanoid/non-secure';
import BaseRouter from './BaseRouter';
export const StackActions = {
replace(name, params) {
return {
type: 'REPLACE',
payload: {
name,
params
}
};
},
push(name, params) {
return {
type: 'PUSH',
payload: {
name,
params
}
};
},
pop() {
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
return {
type: 'POP',
payload: {
count
}
};
},
popToTop() {
return {
type: 'POP_TO_TOP'
};
}
};
export default function StackRouter(options) {
const router = {
...BaseRouter,
type: 'stack',
getInitialState(_ref) {
let {
routeNames,
routeParamList
} = _ref;
const initialRouteName = options.initialRouteName !== undefined && routeNames.includes(options.initialRouteName) ? options.initialRouteName : routeNames[0];
return {
stale: false,
type: 'stack',
key: `stack-${nanoid()}`,
index: 0,
routeNames,
routes: [{
key: `${initialRouteName}-${nanoid()}`,
name: initialRouteName,
params: routeParamList[initialRouteName]
}]
};
},
getRehydratedState(partialState, _ref2) {
let {
routeNames,
routeParamList
} = _ref2;
let state = partialState;
if (state.stale === false) {
return state;
}
const routes = state.routes.filter(route => routeNames.includes(route.name)).map(route => ({
...route,
key: route.key || `${route.name}-${nanoid()}`,
params: routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...route.params
} : route.params
}));
if (routes.length === 0) {
const initialRouteName = options.initialRouteName !== undefined ? options.initialRouteName : routeNames[0];
routes.push({
key: `${initialRouteName}-${nanoid()}`,
name: initialRouteName,
params: routeParamList[initialRouteName]
});
}
return {
stale: false,
type: 'stack',
key: `stack-${nanoid()}`,
index: routes.length - 1,
routeNames,
routes
};
},
getStateForRouteNamesChange(state, _ref3) {
let {
routeNames,
routeParamList,
routeKeyChanges
} = _ref3;
const routes = state.routes.filter(route => routeNames.includes(route.name) && !routeKeyChanges.includes(route.name));
if (routes.length === 0) {
const initialRouteName = options.initialRouteName !== undefined && routeNames.includes(options.initialRouteName) ? options.initialRouteName : routeNames[0];
routes.push({
key: `${initialRouteName}-${nanoid()}`,
name: initialRouteName,
params: routeParamList[initialRouteName]
});
}
return {
...state,
routeNames,
routes,
index: Math.min(state.index, routes.length - 1)
};
},
getStateForRouteFocus(state, key) {
const index = state.routes.findIndex(r => r.key === key);
if (index === -1 || index === state.index) {
return state;
}
return {
...state,
index,
routes: state.routes.slice(0, index + 1)
};
},
getStateForAction(state, action, options) {
const {
routeParamList
} = options;
switch (action.type) {
case 'REPLACE':
{
const index = action.target === state.key && action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
if (index === -1) {
return null;
}
const {
name,
key,
params
} = action.payload;
if (!state.routeNames.includes(name)) {
return null;
}
return {
...state,
routes: state.routes.map((route, i) => i === index ? {
key: key !== undefined ? key : `${name}-${nanoid()}`,
name,
params: routeParamList[name] !== undefined ? {
...routeParamList[name],
...params
} : params
} : route)
};
}
case 'PUSH':
if (state.routeNames.includes(action.payload.name)) {
const getId = options.routeGetIdList[action.payload.name];
const id = getId === null || getId === void 0 ? void 0 : getId({
params: action.payload.params
});
const route = id ? state.routes.find(route => route.name === action.payload.name && id === (getId === null || getId === void 0 ? void 0 : getId({
params: route.params
}))) : undefined;
let routes;
if (route) {
routes = state.routes.filter(r => r.key !== route.key);
routes.push({
...route,
params: routeParamList[action.payload.name] !== undefined ? {
...routeParamList[action.payload.name],
...action.payload.params
} : action.payload.params
});
} else {
routes = [...state.routes, {
key: `${action.payload.name}-${nanoid()}`,
name: action.payload.name,
params: routeParamList[action.payload.name] !== undefined ? {
...routeParamList[action.payload.name],
...action.payload.params
} : action.payload.params
}];
}
return {
...state,
index: routes.length - 1,
routes
};
}
return null;
case 'POP':
{
const index = action.target === state.key && action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
if (index > 0) {
const count = Math.max(index - action.payload.count + 1, 1);
const routes = state.routes.slice(0, count).concat(state.routes.slice(index + 1));
return {
...state,
index: routes.length - 1,
routes
};
}
return null;
}
case 'POP_TO_TOP':
return router.getStateForAction(state, {
type: 'POP',
payload: {
count: state.routes.length - 1
}
}, options);
case 'NAVIGATE':
if (action.payload.name !== undefined && !state.routeNames.includes(action.payload.name)) {
return null;
}
if (action.payload.key || action.payload.name) {
// If the route already exists, navigate to that
let index = -1;
const getId =
// `getId` and `key` can't be used together
action.payload.key === undefined && action.payload.name !== undefined ? options.routeGetIdList[action.payload.name] : undefined;
const id = getId === null || getId === void 0 ? void 0 : getId({
params: action.payload.params
});
if (id) {
index = state.routes.findIndex(route => route.name === action.payload.name && id === (getId === null || getId === void 0 ? void 0 : getId({
params: route.params
})));
} else if (state.routes[state.index].name === action.payload.name && action.payload.key === undefined || state.routes[state.index].key === action.payload.key) {
index = state.index;
} else {
for (let i = state.routes.length - 1; i >= 0; i--) {
if (state.routes[i].name === action.payload.name && action.payload.key === undefined || state.routes[i].key === action.payload.key) {
index = i;
break;
}
}
}
if (index === -1 && action.payload.key && action.payload.name === undefined) {
return null;
}
if (index === -1 && action.payload.name !== undefined) {
const routes = [...state.routes, {
key: action.payload.key ?? `${action.payload.name}-${nanoid()}`,
name: action.payload.name,
path: action.payload.path,
params: routeParamList[action.payload.name] !== undefined ? {
...routeParamList[action.payload.name],
...action.payload.params
} : action.payload.params
}];
return {
...state,
routes,
index: routes.length - 1
};
}
const route = state.routes[index];
let params;
if (action.payload.merge) {
params = action.payload.params !== undefined || routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...route.params,
...action.payload.params
} : route.params;
} else {
params = routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...action.payload.params
} : action.payload.params;
}
return {
...state,
index,
routes: [...state.routes.slice(0, index), params !== route.params || action.payload.path && action.payload.path !== route.path ? {
...route,
path: action.payload.path ?? route.path,
params
} : state.routes[index]]
};
}
return null;
case 'GO_BACK':
if (state.index > 0) {
return router.getStateForAction(state, {
type: 'POP',
payload: {
count: 1
},
target: action.target,
source: action.source
}, options);
}
return null;
default:
return BaseRouter.getStateForAction(state, action);
}
},
actionCreators: StackActions
};
return router;
}
//# sourceMappingURL=StackRouter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,250 @@
import { nanoid } from 'nanoid/non-secure';
import BaseRouter from './BaseRouter';
const TYPE_ROUTE = 'route';
export const TabActions = {
jumpTo(name, params) {
return {
type: 'JUMP_TO',
payload: {
name,
params
}
};
}
};
const getRouteHistory = (routes, index, backBehavior, initialRouteName) => {
const history = [{
type: TYPE_ROUTE,
key: routes[index].key
}];
let initialRouteIndex;
switch (backBehavior) {
case 'order':
for (let i = index; i > 0; i--) {
history.unshift({
type: TYPE_ROUTE,
key: routes[i - 1].key
});
}
break;
case 'firstRoute':
if (index !== 0) {
history.unshift({
type: TYPE_ROUTE,
key: routes[0].key
});
}
break;
case 'initialRoute':
initialRouteIndex = routes.findIndex(route => route.name === initialRouteName);
initialRouteIndex = initialRouteIndex === -1 ? 0 : initialRouteIndex;
if (index !== initialRouteIndex) {
history.unshift({
type: TYPE_ROUTE,
key: routes[initialRouteIndex].key
});
}
break;
case 'history':
// The history will fill up on navigation
break;
}
return history;
};
const changeIndex = (state, index, backBehavior, initialRouteName) => {
let history;
if (backBehavior === 'history') {
const currentKey = state.routes[index].key;
history = state.history.filter(it => it.type === 'route' ? it.key !== currentKey : false).concat({
type: TYPE_ROUTE,
key: currentKey
});
} else {
history = getRouteHistory(state.routes, index, backBehavior, initialRouteName);
}
return {
...state,
index,
history
};
};
export default function TabRouter(_ref) {
let {
initialRouteName,
backBehavior = 'firstRoute'
} = _ref;
const router = {
...BaseRouter,
type: 'tab',
getInitialState(_ref2) {
let {
routeNames,
routeParamList
} = _ref2;
const index = initialRouteName !== undefined && routeNames.includes(initialRouteName) ? routeNames.indexOf(initialRouteName) : 0;
const routes = routeNames.map(name => ({
name,
key: `${name}-${nanoid()}`,
params: routeParamList[name]
}));
const history = getRouteHistory(routes, index, backBehavior, initialRouteName);
return {
stale: false,
type: 'tab',
key: `tab-${nanoid()}`,
index,
routeNames,
history,
routes
};
},
getRehydratedState(partialState, _ref3) {
var _state$routes, _state$history;
let {
routeNames,
routeParamList
} = _ref3;
let state = partialState;
if (state.stale === false) {
return state;
}
const routes = routeNames.map(name => {
const route = state.routes.find(r => r.name === name);
return {
...route,
name,
key: route && route.name === name && route.key ? route.key : `${name}-${nanoid()}`,
params: routeParamList[name] !== undefined ? {
...routeParamList[name],
...(route ? route.params : undefined)
} : route ? route.params : undefined
};
});
const index = Math.min(Math.max(routeNames.indexOf((_state$routes = state.routes[(state === null || state === void 0 ? void 0 : state.index) ?? 0]) === null || _state$routes === void 0 ? void 0 : _state$routes.name), 0), routes.length - 1);
const history = ((_state$history = state.history) === null || _state$history === void 0 ? void 0 : _state$history.filter(it => routes.find(r => r.key === it.key))) ?? [];
return changeIndex({
stale: false,
type: 'tab',
key: `tab-${nanoid()}`,
index,
routeNames,
history,
routes
}, index, backBehavior, initialRouteName);
},
getStateForRouteNamesChange(state, _ref4) {
let {
routeNames,
routeParamList,
routeKeyChanges
} = _ref4;
const routes = routeNames.map(name => state.routes.find(r => r.name === name && !routeKeyChanges.includes(r.name)) || {
name,
key: `${name}-${nanoid()}`,
params: routeParamList[name]
});
const index = Math.max(0, routeNames.indexOf(state.routes[state.index].name));
let history = state.history.filter(
// Type will always be 'route' for tabs, but could be different in a router extending this (e.g. drawer)
it => it.type !== 'route' || routes.find(r => r.key === it.key));
if (!history.length) {
history = getRouteHistory(routes, index, backBehavior, initialRouteName);
}
return {
...state,
history,
routeNames,
routes,
index
};
},
getStateForRouteFocus(state, key) {
const index = state.routes.findIndex(r => r.key === key);
if (index === -1 || index === state.index) {
return state;
}
return changeIndex(state, index, backBehavior, initialRouteName);
},
getStateForAction(state, action, _ref5) {
let {
routeParamList,
routeGetIdList
} = _ref5;
switch (action.type) {
case 'JUMP_TO':
case 'NAVIGATE':
{
let index = -1;
if (action.type === 'NAVIGATE' && action.payload.key) {
index = state.routes.findIndex(route => route.key === action.payload.key);
} else {
index = state.routes.findIndex(route => route.name === action.payload.name);
}
if (index === -1) {
return null;
}
return changeIndex({
...state,
routes: state.routes.map((route, i) => {
if (i !== index) {
return route;
}
const getId = routeGetIdList[route.name];
const currentId = getId === null || getId === void 0 ? void 0 : getId({
params: route.params
});
const nextId = getId === null || getId === void 0 ? void 0 : getId({
params: action.payload.params
});
const key = currentId === nextId ? route.key : `${route.name}-${nanoid()}`;
let params;
if (action.type === 'NAVIGATE' && action.payload.merge && currentId === nextId) {
params = action.payload.params !== undefined || routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...route.params,
...action.payload.params
} : route.params;
} else {
params = routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...action.payload.params
} : action.payload.params;
}
const path = action.type === 'NAVIGATE' && action.payload.path != null ? action.payload.path : route.path;
return params !== route.params || path !== route.path ? {
...route,
key,
path,
params
} : route;
})
}, index, backBehavior, initialRouteName);
}
case 'GO_BACK':
{
if (state.history.length === 1) {
return null;
}
const previousKey = state.history[state.history.length - 2].key;
const index = state.routes.findIndex(route => route.key === previousKey);
if (index === -1) {
return null;
}
return {
...state,
history: state.history.slice(0, -1),
index
};
}
default:
return BaseRouter.getStateForAction(state, action);
}
},
shouldActionChangeFocus(action) {
return action.type === 'NAVIGATE';
},
actionCreators: TabActions
};
return router;
}
//# sourceMappingURL=TabRouter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
import * as CommonActions from './CommonActions';
export { CommonActions };
export { default as BaseRouter } from './BaseRouter';
export { DrawerActions, default as DrawerRouter } from './DrawerRouter';
export { StackActions, default as StackRouter } from './StackRouter';
export { TabActions, default as TabRouter } from './TabRouter';
export * from './types';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["CommonActions","default","BaseRouter","DrawerActions","DrawerRouter","StackActions","StackRouter","TabActions","TabRouter"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,OAAO,KAAKA,aAAa,MAAM,iBAAiB;AAEhD,SAASA,aAAa;AAEtB,SAASC,OAAO,IAAIC,UAAU,QAAQ,cAAc;AAQpD,SAASC,aAAa,EAAEF,OAAO,IAAIG,YAAY,QAAQ,gBAAgB;AAOvE,SAASC,YAAY,EAAEJ,OAAO,IAAIK,WAAW,QAAQ,eAAe;AAOpE,SAASC,UAAU,EAAEN,OAAO,IAAIO,SAAS,QAAQ,aAAa;AAC9D,cAAc,SAAS"}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.tsx"],"mappings":""}