Remove UserStore

This commit is contained in:
Tom Moor
2017-09-03 15:45:25 -07:00
parent f0bd0d0ddb
commit bdb7c46874
4 changed files with 7 additions and 53 deletions

View File

@@ -27,7 +27,6 @@ import SidebarCollection from './components/SidebarCollection';
import SidebarCollectionList from './components/SidebarCollectionList';
import SidebarLink from './components/SidebarLink';
import UserStore from 'stores/UserStore';
import AuthStore from 'stores/AuthStore';
import UiStore from 'stores/UiStore';
import CollectionsStore from 'stores/CollectionsStore';
@@ -40,7 +39,6 @@ type Props = {
children?: ?React.Element<any>,
actions?: ?React.Element<any>,
title?: ?React.Element<any>,
user: UserStore,
auth: AuthStore,
ui: UiStore,
search: ?boolean,
@@ -108,7 +106,8 @@ type Props = {
};
render() {
const { user, auth, documents, collections, history, ui } = this.props;
const { auth, documents, collections, history, ui } = this.props;
const { user } = auth;
return (
<Container column auto>
@@ -134,7 +133,7 @@ type Props = {
<Flex align="center">
<LogoLink to="/">Atlas</LogoLink>
</Flex>
<DropdownMenu label={<Avatar src={user.user.avatarUrl} />}>
<DropdownMenu label={<Avatar src={user.avatarUrl} />}>
<DropdownMenuItem onClick={this.handleOpenSettings}>
Settings
</DropdownMenuItem>

View File

@@ -51,23 +51,22 @@ type AuthProps = {
};
const Auth = ({ children }: AuthProps) => {
if (stores.auth.authenticated && stores.auth.team) {
if (stores.auth.authenticated && stores.auth.team && stores.auth.user) {
// Only initialize stores once. Kept in global scope
// because otherwise they will get overriden on route
// change
if (!authenticatedStores) {
// Stores for authenticated user
const user = stores.auth.getUserStore();
const cache = new CacheStore(user.user.id);
const { user, team } = stores.auth;
const cache = new CacheStore(user.id);
authenticatedStores = {
user,
documents: new DocumentsStore({
ui: stores.ui,
cache,
}),
collections: new CollectionsStore({
ui: stores.ui,
teamId: user.team.id,
teamId: team.id,
cache,
}),
};

View File

@@ -2,7 +2,6 @@
import { observable, action, computed, autorunAsync } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import UserStore from 'stores/UserStore';
import type { User, Team } from 'types';
const AUTH_STORE = 'AUTH_STORE';
@@ -72,17 +71,6 @@ class AuthStore {
};
};
getUserStore(): UserStore {
invariant(
this.user && this.team,
'Tried to create a user store without data'
);
return new UserStore({
user: this.user,
team: this.team,
});
}
constructor() {
// Rehydrate
const data = JSON.parse(localStorage.getItem(AUTH_STORE) || '{}');

View File

@@ -1,32 +0,0 @@
// @flow
import { observable, computed } from 'mobx';
import type { User, Team } from 'types';
type Options = {
user: User,
team: Team,
};
class UserStore {
@observable user: User;
@observable team: Team;
@observable isLoading: boolean = false;
/* Computed */
@computed get asJson(): string {
return JSON.stringify({
user: this.user,
team: this.team,
});
}
constructor(options: Options) {
// Rehydrate
this.user = options.user;
this.team = options.team;
}
}
export default UserStore;