Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as React from 'react'
import { useStore } from 'effector-react'
import { useStore, useGate } from 'effector-react'

import './App.css'
import { Theater } from '../Theater'
import { Auth } from '../Auth'

import {$user} from '../../models/auth'
import { $user } from '../../models/auth'
import {AppGate} from '../../models/app'

export const App = () => {
useGate(AppGate)
const {email} = useStore($user)
return email ? (<Theater />) : (<Auth />)
}
5 changes: 4 additions & 1 deletion src/models/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {createEffect} from 'effector'
import { createGate } from 'effector-react'

import { Config } from './types'

export const initAppFx = createEffect<Config, unknown>()
export const initAppFx = createEffect<Config, unknown>()

export const AppGate = createGate()
11 changes: 10 additions & 1 deletion src/models/app/init.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { initializeApp } from 'firebase'
import { forward } from 'effector'

import {
initAppFx
initAppFx, AppGate
} from './'

import { fetchUsersFx } from '../users'

import {
appId,
projectId,
apiKey,
messagingSenderId
} from '../../../config.json'


initAppFx.use(async ({
appId,
projectId,
Expand All @@ -33,4 +37,9 @@ initAppFx({
projectId,
apiKey,
messagingSenderId
})

forward({
from: AppGate.open,
to: fetchUsersFx
})
16 changes: 15 additions & 1 deletion src/models/auth/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {

import {
addUserFx,
updateUsersTableFx
updateUsersTableFx,
deleteUserFx,
$firebaseUsers
} from '../users'

const gProvider = new auth.GoogleAuthProvider()
Expand Down Expand Up @@ -77,4 +79,16 @@ forward({
}
}),
to: signUpViaEmailFx
})

sample({
source: $firebaseUsers,
clock: logout,
//@ts-ignore
fn: (users, email) => Object.keys(users).find((id) => {
if (email === users[id].email) {
return id
}
}),
target: deleteUserFx
})
3 changes: 2 additions & 1 deletion src/models/init.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './app/init'
import './auth/init'
import './users/init'
import './users/init'
import './tables/init'
30 changes: 28 additions & 2 deletions src/models/tables/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
import {createStore} from 'effector'
import {createStore, createEvent} from 'effector'

export const $currentConnectID = createStore('first-table')
export const updateCurrentIDandStage = createEvent<{ ID: string, stage: number }>()

export const $currentConnectID = createStore<string>('first-table')

export const $tableIDs = createStore<string[]>([
'first-table',
'second-table',
'third-table',
'fourth-table',
'fifth-table',
'sixth-table',
'seventh-table',
'eighth-table',
'ninth-table',
'tenth-table',
'eleventh-table',
'twelfth-table',
'thirteenth-table',
'fourteenth-table',
'fifteenth-table',
'left-top-table',
'right-top-table',
'left-bottom-table',
'right-bottom-table'
])

export const $stage = createStore(2)
4 changes: 2 additions & 2 deletions src/models/tables/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
$currentConnectID,
$tableIDs,
$stage
} from './'
} from './index'

import {
$tableUsers
} from '../users'
} from '../users/index'

sample({
source: {
Expand Down
14 changes: 14 additions & 0 deletions src/models/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,18 @@ export const $usersByEmail = $firebaseUsers.map((fUsers) => {
...usersByEmail
}
}, {})
})

export const $tableUsers = $firebaseUsers.map((fUsers) => {
return Object.keys(fUsers).reduce<TableIDUsersMap>((tableUsers, id) => {
const tableID = fUsers[id].tableID;
if (tableUsers[tableID] !== undefined) {
tableUsers[tableID].push(fUsers[id]);
return tableUsers;
}
return {
...tableUsers,
[tableID]: [fUsers[id]]
}
}, {})
})