Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function * deleteTournamentSaga () {
const firebase = getFirebase()
yield takeEvery(DELETE_TOURNAMENT, function * (action) {
const { tournamentId } = action.payload
const auth = yield select(state => pathToJS(state.firebase, 'auth'))
if (!auth) { return }
const { uid } = auth
const db = firebase.database()
const ref = db.ref()
try {
yield ref.update({
[`/tournaments/${tournamentId}`]: null,
[`/publishData/${tournamentId}`]: null,
[`/tournamentsByOwner/${uid}/${tournamentId}`]: null
export default function * syncTournamentSaga () {
const firebase = getFirebase()
let fetchTask = null
let pushTask = null
let reconciler = null
while (true) {
const { payload } = yield take(REQUEST_TOURNAMENT)
if (fetchTask) {
fetchTask.cancel()
fetchTask = null
}
if (pushTask) {
pushTask.cancel()
pushTask = null
}
export default function * createTournamentSaga () {
const firebase = getFirebase()
yield takeEvery(CREATE_TOURNAMENT, function * (action) {
const { title, tournament, revision } = action.payload
const auth = yield select(state => pathToJS(state.firebase, 'auth'))
if (!auth) { return }
const { uid } = auth
const db = firebase.database()
const ref = db.ref()
const newKey = ref.child('tournaments').push().key
const lastModified = firebase.database.ServerValue.TIMESTAMP
try {
yield ref.update({
[`/tournaments/${newKey}`]: {
function * publishRequestSaga (tournamentId, { payload }) {
const firebase = getFirebase()
const db = firebase.database()
try {
const auth = yield select(state => pathToJS(state.firebase, 'auth'))
if (!auth) { throw new Error('Needs authentication') }
const { uid } = auth
let data = yield select(state => state.tournament.data)
if (!data) { throw new Error('No tournament data to publish') }
if (payload.censored) {
data = censor(data)
}
let publishId = (yield db.ref(`/publishData/${tournamentId}/id`).once('value')).val()
if (!publishId) { publishId = db.ref('/publishedTournaments').push().key }
function * publishIdRequestSaga (tournamentId, { payload }) {
const firebase = getFirebase()
const db = firebase.database()
try {
const publishData = (yield db.ref(`/publishData/${tournamentId}`).once('value')).val()
if (!publishData) {
yield put(getPublishIdResponse({
timestamp: null,
id: null,
params: null
}))
} else {
const { timestamp, id, params } = publishData
yield put(getPublishIdResponse({ timestamp, id, params }))
}
} catch (ex) {