Public Access
feat(dashboard): pick the banner game or turn the banner off
This commit is contained in:
1 parent
23e502bf5b
commit
83494519f9
11 files changed
+137
-23
No files matched your search
@@ -2,7 +2,12 @@
|
||||
export const ACCENTS = ['violet', 'blue', 'green', 'orange', 'pink', 'red'];
|
||||
export const CORNERS = ['sharp', 'default', 'round'];
|
||||
|
||||
export const DEFAULT_APPEARANCE = {accent: 'violet', corners: 'default', wideLayout: false, backgroundAppid: null};
|
||||
// bannerAppid null: the dashboard banner shows the game played most in the last two weeks.
|
||||
export const DEFAULT_APPEARANCE = {
|
||||
accent: 'violet', corners: 'default', wideLayout: false, backgroundAppid: null, bannerAppid: null, showBanner: true,
|
||||
};
|
||||
|
||||
const appid = (value) => (Number.isInteger(value) && value > 0 ? value : null);
|
||||
|
||||
const STORAGE_KEY = 'tbp_appearance';
|
||||
const REQUEST_TIMEOUT_MS = 10000;
|
||||
@@ -11,7 +16,9 @@ export const normalizeAppearance = (value) => ({
|
||||
accent: ACCENTS.includes(value?.accent) ? value.accent : DEFAULT_APPEARANCE.accent,
|
||||
corners: CORNERS.includes(value?.corners) ? value.corners : DEFAULT_APPEARANCE.corners,
|
||||
wideLayout: value?.wideLayout === true,
|
||||
backgroundAppid: Number.isInteger(value?.backgroundAppid) && value.backgroundAppid > 0 ? value.backgroundAppid : null,
|
||||
backgroundAppid: appid(value?.backgroundAppid),
|
||||
bannerAppid: appid(value?.bannerAppid),
|
||||
showBanner: value?.showBanner !== false,
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,13 +10,13 @@ import {
|
||||
|
||||
describe('normalizeAppearance', () => {
|
||||
it('keeps known values', () => {
|
||||
const appearance = {accent: 'blue', corners: 'round', wideLayout: true, backgroundAppid: 620};
|
||||
const appearance = {accent: 'blue', corners: 'round', wideLayout: true, backgroundAppid: 620, bannerAppid: 1086940, showBanner: false};
|
||||
|
||||
expect(normalizeAppearance(appearance)).toEqual(appearance);
|
||||
});
|
||||
|
||||
it('replaces unknown or missing values with the defaults', () => {
|
||||
expect(normalizeAppearance({accent: 'red;x', corners: 'pointy', wideLayout: 'yes', backgroundAppid: -1}))
|
||||
expect(normalizeAppearance({accent: 'red;x', corners: 'pointy', wideLayout: 'yes', backgroundAppid: -1, bannerAppid: '620', showBanner: 'no'}))
|
||||
.toEqual(DEFAULT_APPEARANCE);
|
||||
expect(normalizeAppearance(null)).toEqual(DEFAULT_APPEARANCE);
|
||||
expect(normalizeAppearance({backgroundAppid: 1.5})).toEqual(DEFAULT_APPEARANCE);
|
||||
@@ -27,9 +27,9 @@ describe('appearance cache', () => {
|
||||
afterEach(() => localStorage.clear());
|
||||
|
||||
it('reads back what was cached', () => {
|
||||
cacheAppearance({accent: 'green', corners: 'sharp', wideLayout: false, backgroundAppid: null});
|
||||
cacheAppearance({accent: 'green', corners: 'sharp', wideLayout: false, backgroundAppid: null, bannerAppid: 620, showBanner: true});
|
||||
|
||||
expect(readCachedAppearance()).toEqual({accent: 'green', corners: 'sharp', wideLayout: false, backgroundAppid: null});
|
||||
expect(readCachedAppearance()).toEqual({accent: 'green', corners: 'sharp', wideLayout: false, backgroundAppid: null, bannerAppid: 620, showBanner: true});
|
||||
});
|
||||
|
||||
it('falls back to the defaults for a broken or empty cache', () => {
|
||||
|
||||
Reference in new issue
Block a user