Generate and append a unique ID to each item

This commit is contained in:
Alicia Sykes
2021-10-16 16:41:10 +01:00
parent 8c3a8e996f
commit 7a817c17d4
3 changed files with 35 additions and 14 deletions

View File

@@ -13,6 +13,7 @@ import {
layout as defaultLayout,
} from '@/utils/defaults';
import ErrorHandler from '@/utils/ErrorHandler';
import { applyItemId } from '@/utils/MiscHelpers';
import conf from '../../public/conf.yml';
export default class ConfigAccumulator {
@@ -57,18 +58,24 @@ export default class ConfigAccumulator {
/* Sections */
sections() {
let sections = [];
// If the user has stored sections in local storage, return those
const localSections = localStorage[localStorageKeys.CONF_SECTIONS];
if (localSections) {
try {
const json = JSON.parse(localSections);
if (json.length >= 1) return json;
if (json.length >= 1) sections = json;
} catch (e) {
ErrorHandler('Malformed section data in local storage');
}
}
// If the function hasn't yet returned, then return the config file sections
return this.conf ? this.conf.sections || [] : [];
// If sections were not set from local data, then use config file instead
if (sections.length === 0) {
sections = this.conf ? this.conf.sections || [] : [];
}
// Apply a unique ID to each item
sections = applyItemId(sections);
return sections;
}
/* Complete config */