mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 20:26:40 +00:00
Extracted short-url related services to its own service provider
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { range } from 'ramda';
|
||||
import PropTypes from 'prop-types';
|
||||
import storage from './Storage';
|
||||
|
||||
const HEX_COLOR_LENGTH = 6;
|
||||
const { floor, random } = Math;
|
||||
@@ -13,7 +12,7 @@ const buildRandomColor = () =>
|
||||
}`;
|
||||
const normalizeKey = (key) => key.toLowerCase().trim();
|
||||
|
||||
export class ColorGenerator {
|
||||
export default class ColorGenerator {
|
||||
constructor(storage) {
|
||||
this.storage = storage;
|
||||
this.colors = this.storage.get('colors') || {};
|
||||
@@ -45,7 +44,3 @@ export const colorGeneratorType = PropTypes.shape({
|
||||
getColorForKey: PropTypes.func,
|
||||
setColorForKey: PropTypes.func,
|
||||
});
|
||||
|
||||
const colorGenerator = new ColorGenerator(storage);
|
||||
|
||||
export default colorGenerator;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const PREFIX = 'shlink';
|
||||
const buildPath = (path) => `${PREFIX}.${path}`;
|
||||
|
||||
export class Storage {
|
||||
export default class Storage {
|
||||
constructor(localStorage) {
|
||||
this.localStorage = localStorage;
|
||||
}
|
||||
@@ -14,15 +14,3 @@ export class Storage {
|
||||
|
||||
set = (key, value) => this.localStorage.setItem(buildPath(key), JSON.stringify(value));
|
||||
}
|
||||
|
||||
const browserStorage = global.localStorage || {
|
||||
getItem() {
|
||||
return '';
|
||||
},
|
||||
setItem() {
|
||||
return '';
|
||||
},
|
||||
};
|
||||
const storage = new Storage(browserStorage);
|
||||
|
||||
export default storage;
|
||||
|
||||
Reference in New Issue
Block a user