export function openModal(product) {
return dispatch => {
dispatch({
type: OPEN_PRODUCT_MODAL,
product
});
};
}
// ...
case OPEN_PRODUCT_MODAL: {
return state.setIn(["catalog", "isProductModalOpen"], true);
// И тут же в стор ложить открытый продукт, который потом в connect будет запрашиваться из стора и передаваться в модальное окно?
}
// ...
import * as admin from "firebase-admin";
const serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: `https://${appName}.firebaseio.com`
});
import * as admin from "firebase-admin";
export function deleteUser(userUid) {
return dispatch => {
dispatch({
type: DELETE_USER_REQUEST
});
admin.auth().deleteUser(userUid).then(() => {
dispatch({
type: DELETE_USER_SUCCESS,
payload: {
userUid
}
});
});
};
}
export const fetchAllProductsToCartSaga = function * () {
const userUid = yield select(state => state["auth"].user.uid); // !!!
const productsRef = firebase.database().ref("users/" + userUid + "/products");
const products = yield call([productsRef, productsRef.once], "value");
yield put({
type: FETCH_ALL_PRODUCTS_TO_CART_SUCCESS,
payload: products.val()
});
};
import { saga as authSaga } from "../ducks/auth";
import { saga as catalogSaga } from "../ducks/catalog";
import { saga as usersSaga } from "../ducks/users";
import { saga as cartSaga } from "../ducks/cart";
import { all } from "redux-saga/effects";
export default function * rootSaga() {
yield all([
authSaga(),
usersSaga(),
catalogSaga(),
cartSaga()
]);
}
const sagaMiddleware = createSagaMiddleware();
const enhancer = applyMiddleware(sagaMiddleware, routerMiddleware(history));
const store = createStore(reducer, window.__REDUX_DEVTOOLS_EXTENSION__(), enhancer);
sagaMiddleware.run(rootSaga);
export default store;
export const signInSaga = function * () {
const auth = firebase.auth();
const action = yield take(SIGN_IN_REQUEST);
const user = yield call([auth, auth.signInWithEmailAndPassword], action.payload.email, action.payload.password);
yield put({
type: SIGN_IN_SUCCESS,
payload: user
});
yield put(replace("/"));
};
export const signOutSaga = function * () {
const auth = firebase.auth();
yield apply(auth, auth.signOut);
}
export const signUpSaga = function * () {
const auth = firebase.auth();
while (true) {
const action = yield take(SIGN_UP_REQUEST);
try {
const user = yield call([auth, auth.createUserWithEmailAndPassword], action.payload.email, action.payload.password);
yield put({
type: SIGN_UP_SUCCESS,
payload: {
user
}
});
firebase.database().ref("users/" + user.uid).set({
email: user.email
});
yield put(replace("/"));
} catch (error) {
yield put({
type: SIGN_UP_ERROR,
error
});
}
}
};
const createAuthChannel = () => eventChannel(emit => firebase.auth().onAuthStateChanged(user => emit({ user })))
export const watchStatusChangeSaga = function * () {
const chan = yield call(createAuthChannel);
while (true) {
const { user } = yield take(chan);
if (user) {
yield put({
type: SIGN_IN_SUCCESS,
payload: { user }
});
} else {
yield put({
type: SIGN_OUT_SUCCESS,
payload: { user }
});
yield put(replace('/'));
}
}
}
export const saga = function * () {
yield all([
takeEvery(SIGN_IN_REQUEST, signInSaga),
takeEvery(SIGN_OUT_REQUEST, signOutSaga),
signUpSaga(),
watchStatusChangeSaga()
]);
};
export const fetchAllProductsToCartSaga = function * () {
const userUid = yield select(state => state["auth"].user.uid);
const productsRef = firebase.database().ref("users/" + userUid + "/products");
const products = yield call([productsRef, productsRef.once], "value");
yield put({
type: FETCH_ALL_PRODUCTS_TO_CART_SUCCESS,
payload: products.val()
});
};
export const addProductToCartSaga = function * (action) {
const { productUid, userUid } = action.payload;
const productRef = firebase.database().ref(`catalog/${productUid}`);
const product = yield call([productRef, productRef.once], "value");
yield put({
type: ADD_PRODUCT_TO_CART_SUCCESS,
payload: {
productUid,
product: product.val()
}
});
pushProductToUser(productUid, userUid);
};
export const saga = function * () {
yield all([
takeEvery(FETCH_ALL_PRODUCTS_TO_CART_REQUEST, fetchAllProductsToCartSaga),
takeEvery(ADD_PRODUCT_TO_CART_REQUEST, addProductToCartSaga)
]);
}
productIdSelector = (_, props) => props.product.id;
ref.on('value', function(dataSnapshot) {
...
});
componentDidMount() {
this.props.fetchAllUsers();
}
export const fetchAllUsersSaga = function * () {
const ref = firebase.database().ref("users");
try {
const data = yield call([ref, ref.once], "value");
yield put({
type: FETCH_ALL_SUCCESS,
payload: data.val()
});
} catch (error) {
// NOP
}
};
export const backgroundSyncSaga = function * () {
try {
while (true) {
yield call(fetchAllUsersSaga);
yield delay(2000);
}
} catch (error) {
// NOP
}
};
export const saga = function * () {
yield fork(backgroundSyncSaga);
yield all([
takeEvery(FETCH_ALL_REQUEST, fetchAllUsersSaga),
]);
};
Вот я про это и говорил. Это не совсем то что хотелось бы. Даже пусть не тему меняющую весь интерфейс, но лучше даже было бы получить готовые цветовые схемы для редактора кода. Настраивать каждый цвет самому это такое себе дело.