aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/preferences.js
blob: 24fe389a80c2541799092ebde09cf3d7b43a04e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { useSelector } from 'react-redux';

export const usePreference = (key, defaultValue) => {
  return useSelector(state => {
    if (state.session.server.forceSettings) {
      return state.session.server[key] || state.session.user[key] || defaultValue;
    } else {
      return state.session.user[key] || state.session.server[key] || defaultValue;
    }
  });
};

export const useAttributePreference = (key, defaultValue) => {
  return useSelector(state => {
    if (state.session.server.forceSettings) {
      return state.session.server.attributes[key] || state.session.user.attributes[key] || defaultValue;
    } else {
      return state.session.user.attributes[key] || state.session.server.attributes[key] || defaultValue;
    }
  });
};