Files
remark42/frontend/app/utils/get-hidden-users.ts
T
Pavel MineevandUmputun 7ce400a5e5 move getting of hidden users to utils
* get hidden user by util
* add tests for changed actions
* add tests for getting users from local storage
2020-03-25 01:52:46 -05:00

18 lines
574 B
TypeScript

import { User } from '@app/common/types';
import { getItem } from '@app/common/local-storage';
import { LS_HIDDEN_USERS_KEY } from '@app/common/constants';
export default function getHiddenUsers() {
try {
const hiddenUsers: Record<string, User> = JSON.parse(getItem(LS_HIDDEN_USERS_KEY) || '{}');
if (typeof hiddenUsers === 'object' && hiddenUsers !== null && !Array.isArray(hiddenUsers)) {
return hiddenUsers;
}
} catch (e) {
console.error('incorrect hidden user data in local storage', e); // eslint-disable-line no-console
}
return {};
}