Delegate tag color storage to ShlinkWebComponent consuming app

This commit is contained in:
Alejandro Celaya
2023-08-06 13:54:57 +02:00
parent 9f9f3b6402
commit 89e75653d7
12 changed files with 53 additions and 65 deletions

View File

@@ -0,0 +1,15 @@
import type { TagColorsStorage as BaseTagColorsStorage } from '@shlinkio/shlink-web-component';
import type { LocalStorage } from './LocalStorage';
export class TagColorsStorage implements BaseTagColorsStorage {
constructor(private readonly storage: LocalStorage) {
}
getTagColors(): Record<string, string> {
return this.storage.get<Record<string, string>>('colors') ?? {};
}
storeTagColors(colors: Record<string, string>): void {
this.storage.set('colors', colors);
}
}

View File

@@ -2,10 +2,12 @@ import type Bottle from 'bottlejs';
import { csvToJson, jsonToCsv } from '../helpers/csvjson';
import { useTimeoutToggle } from '../helpers/hooks';
import { LocalStorage } from './LocalStorage';
import { TagColorsStorage } from './TagColorsStorage';
export const provideServices = (bottle: Bottle) => {
bottle.constant('localStorage', window.localStorage);
bottle.service('Storage', LocalStorage, 'localStorage');
bottle.service('TagColorsStorage', TagColorsStorage, 'Storage');
bottle.constant('csvToJson', csvToJson);
bottle.constant('jsonToCsv', jsonToCsv);