- {websites.map(({ website_id, name, domain }, index) =>
+ {ordered.map(({ website_id, name, domain }, index) =>
index < limit ? (
{
- const bs = { showCharts: !state.showCharts };
- console.log('WTF', { state, bs });
- return bs;
- });
+ saveDashboard(state => ({ showCharts: !state.showCharts }));
}
if (value === 'order') {
saveDashboard({ editing: true });
diff --git a/lib/array.js b/lib/array.js
index 5b9aa1f2..c468168d 100644
--- a/lib/array.js
+++ b/lib/array.js
@@ -9,3 +9,10 @@ export function chunk(arr, size) {
return chunks;
}
+
+export function sortArrayByMap(arr, map = [], key) {
+ if (!arr) return [];
+ if (map.length === 0) return arr;
+
+ return map.map(id => arr.find(item => item[key] === id));
+}
diff --git a/lib/format.js b/lib/format.js
index 26f02f3b..a336c1c4 100644
--- a/lib/format.js
+++ b/lib/format.js
@@ -78,14 +78,3 @@ export function stringToColor(str) {
}
return color;
}
-
-export function orderByWebsiteMap(websites, orderMap) {
- if (!websites) return [];
-
- let ordered = [...websites];
- for (let website of websites) {
- ordered[orderMap[website.website_uuid]] = website;
- }
-
- return ordered;
-}
diff --git a/lib/web.js b/lib/web.js
index ea5513e3..7317d322 100644
--- a/lib/web.js
+++ b/lib/web.js
@@ -69,8 +69,6 @@ export const getItem = (key, session) => {
return JSON.parse(value);
}
}
-
- return null;
};
export const removeItem = (key, session) => {
diff --git a/store/dashboard.js b/store/dashboard.js
index 54d526d0..35f4f2ff 100644
--- a/store/dashboard.js
+++ b/store/dashboard.js
@@ -5,15 +5,14 @@ import { getItem, setItem } from 'lib/web';
export const initialState = {
showCharts: true,
limit: DEFAULT_WEBSITE_LIMIT,
- websiteOrder: {},
+ websiteOrder: [],
editing: false,
};
const store = create(() => ({ ...initialState, ...getItem(DASHBOARD_CONFIG) }));
export function saveDashboard(settings) {
- const state = typeof settings === 'function' ? settings(store.getState()) : settings;
- store.setState(state);
+ store.setState(settings);
setItem(DASHBOARD_CONFIG, store.getState());
}