slate/common/navigation-data.js

213 lines
4.5 KiB
JavaScript
Raw Normal View History

import * as Strings from "~/common/strings";
// NOTE(jim):
// Recursion for nested entities (any number).
export const getCurrentById = (navigation, targetId) => {
let target = null;
let activeIds = {};
const findById = (state, id) => {
for (let i = 0; i < state.length; i++) {
if (state[i].id === id) {
target = state[i];
activeIds[state[i].id] = true;
}
if (!target && state[i].children) {
activeIds[state[i].id] = true;
findById(state[i].children, id);
if (!target) {
activeIds[state[i].id] = false;
}
}
}
};
findById(navigation, targetId);
return { target, activeIds };
};
const constructFilesTreeForNavigation = (library) => {
return {
...library[0],
name: `Data`,
children: [
{
id: "V1_NAVIGATION_ENCRYPTED_DATA",
decorator: "ENCRYPTED",
name: "Encrypted Data",
pageTitle: "Encrypted data",
children: null,
},
],
};
};
const constructSlatesTreeForNavigation = (slates) => {
return slates.map((s) => {
return {
...s,
2020-07-27 11:33:39 +03:00
slateId: s.id,
2020-09-27 23:11:04 +03:00
name: Strings.getPresentationSlateName(s),
pageTitle: `Viewing ${s.slatename}`,
decorator: "SLATE",
2020-09-17 02:26:15 +03:00
ignore: true,
};
});
};
export const generate = ({ library = [], slates = [] }) => [
{
id: "V1_NAVIGATION_HOME",
decorator: "HOME",
2020-06-19 06:57:57 +03:00
name: "Home",
pageTitle: "Welcome back!",
children: null,
},
{
id: "V1_NAVIGATION_DIRECTORY",
decorator: "DIRECTORY",
name: "Directory",
pageTitle: "Your directory",
children: null,
},
{
id: "V1_NAVIGATION_SLATES",
decorator: "SLATES",
name: "Slates",
pageTitle: "Slates",
2020-09-17 02:26:15 +03:00
children: null,
},
{
id: "V1_NAVIGATION_SLATE",
2020-09-04 01:42:08 +03:00
decorator: "PUBLIC_SLATE",
name: "Slate",
pageTitle: "Slate",
children: null,
ignore: true,
},
{
id: "V1_NAVIGATION_TARA",
decorator: "TARA",
name: "Tara",
pageTitle: "Tara Sandbox",
children: null,
ignore: true,
},
2020-09-17 02:26:15 +03:00
...constructSlatesTreeForNavigation(slates),
constructFilesTreeForNavigation(library),
2020-08-25 05:31:42 +03:00
/*
{
id: "V1_NAVIGATION_LOCAL",
decorator: "LOCAL_DATA",
name: "Local",
pageTitle: "Your local data",
children: [],
ignore: false,
},
{
id: "V1_NAVIGATION_WALLET",
decorator: "WALLET",
name: "Wallet",
pageTitle: "Your wallet and addresses",
children: [
],
2020-08-25 05:31:42 +03:00
},
{
id: "V1_NAVIGATION_NETWORK",
decorator: "NETWORK",
name: "Network",
pageTitle: "The Filecoin Network",
children: null,
},
2020-08-25 05:31:42 +03:00
*/
2020-08-04 10:35:55 +03:00
{
id: "V1_NAVIGATION_API",
decorator: "SETTINGS_DEVELOPER",
name: "API",
pageTitle: "Developer API",
2020-09-09 20:56:35 +03:00
children: [],
},
{
id: "V1_NAVIGATION_ARCHIVE",
decorator: "FILECOIN",
name: "Filecoin",
2020-09-09 20:56:35 +03:00
pageTitle: "Archive on Filecoin",
2020-09-25 10:08:08 +03:00
filecoin: true,
children: [
{
id: "V1_NAVIGATION_NETWORK",
decorator: "NETWORK",
2020-09-09 20:56:35 +03:00
name: "Network API",
pageTitle: "The Filecoin Network",
children: null,
2020-09-25 10:08:08 +03:00
filecoin: true,
},
2020-09-09 20:56:35 +03:00
{
id: "V1_NAVIGATION_FILECOIN_SETTINGS",
decorator: "SETTINGS",
2020-09-23 12:46:59 +03:00
name: "Deal Settings",
2020-09-09 20:56:35 +03:00
pageTitle: "Deal Settings.",
2020-09-25 10:08:08 +03:00
filecoin: true,
2020-09-09 20:56:35 +03:00
children: null,
},
{
id: "V1_NAVIGATION_DEAL_HISTORY",
decorator: "DEALS",
name: "Deal History",
pageTitle: "Storage Deal History",
filecoin: true,
},
{
id: "V1_NAVIGATION_WALLET",
decorator: "WALLET",
name: "Wallet",
pageTitle: "Your wallet and addresses",
children: [],
filecoin: true,
},
2020-09-27 19:38:20 +03:00
{
id: "V1_NAVIGATION_MINERS",
decorator: "MINERS",
name: "Miners",
pageTitle: "Miners",
2020-09-27 19:38:20 +03:00
filecoin: true,
children: null,
},
],
},
{
id: "V1_NAVIGATION_FILECOIN_STORAGE_DEAL",
decorator: "MAKE_DEAL",
2020-09-23 12:46:59 +03:00
name: "Storage Deal",
2020-09-25 10:08:08 +03:00
filecoin: true,
2020-09-23 12:46:59 +03:00
pageTitle: "Make an one-off Filecoin storage deal",
2020-09-23 05:39:46 +03:00
},
{
id: "V1_NAVIGATION_PROFILE_EDIT",
decorator: "EDIT_ACCOUNT",
name: "Profile & Account Settings",
pageTitle: "Your Profile & Account Settings",
children: null,
ignore: true,
},
{
id: "V1_NAVIGATION_PROFILE",
2020-09-04 01:42:08 +03:00
decorator: "PUBLIC_PROFILE",
name: "Profile",
pageTitle: "Profile",
children: null,
ignore: true,
},
{
id: "V1_NAVIGATION_FILE",
decorator: "FILE",
name: "File",
pageTitle: "File",
children: null,
ignore: true,
},
];