diff --git a/client/src/store/sagas/failure.ts b/client/src/store/sagas/failure.ts index 24e6fb5..b76ae21 100644 --- a/client/src/store/sagas/failure.ts +++ b/client/src/store/sagas/failure.ts @@ -1,9 +1,11 @@ import { GiteaUnauthorizedError } from "../../util/gitea"; import { put } from 'redux-saga/effects'; import { logout } from '../actions/logout'; +import { saveReferer } from "../../util/referer"; export function* failuresSaga(action) { if (action.error instanceof GiteaUnauthorizedError) { + saveReferer(); yield put(logout()); } } diff --git a/client/src/store/sagas/referer.ts b/client/src/store/sagas/referer.ts new file mode 100644 index 0000000..69515bc --- /dev/null +++ b/client/src/store/sagas/referer.ts @@ -0,0 +1,9 @@ +import { hasReferer, getReferer, clearReferer } from '../../util/referer'; + +export function* navigateToRefererSaga() { + if (!hasReferer()) return; + const referer = getReferer(); + console.log("Redirecting to referer", referer); + clearReferer(); + window.location.hash = referer; +} \ No newline at end of file diff --git a/client/src/store/sagas/root.ts b/client/src/store/sagas/root.ts index f0f6818..89431fd 100644 --- a/client/src/store/sagas/root.ts +++ b/client/src/store/sagas/root.ts @@ -10,9 +10,11 @@ import { LOGOUT_REQUEST, LOGOUT_SUCCESS } from '../actions/logout'; import { logoutSaga, logoutSuccessSaga } from './logout'; import { BUILD_KANBOARD_REQUEST, MOVE_CARD } from '../actions/kanboards'; import { buildKanboardSaga, moveCardSaga, refreshKanboardSaga } from './kanboards'; +import { navigateToRefererSaga } from './referer'; export function* rootSaga() { yield all([ + navigateToRefererSaga(), takeEvery(patternFromRegExp(/^.*_FAILURE/), failuresSaga), takeLatest(FETCH_BOARDS_REQUEST, fetchBoardsSaga), takeLatest(BUILD_KANBOARD_REQUEST, buildKanboardSaga), diff --git a/client/src/util/referer.ts b/client/src/util/referer.ts new file mode 100644 index 0000000..ad124a4 --- /dev/null +++ b/client/src/util/referer.ts @@ -0,0 +1,19 @@ +const localStorage = window.localStorage; +const refererKey = 'referer'; + +export function getReferer() { + return localStorage.getItem(refererKey); +} + +export function saveReferer() { + console.log("Saving referer", window.location.hash); + localStorage.setItem(refererKey, window.location.hash); +} + +export function hasReferer() { + return !!getReferer(); +} + +export function clearReferer() { + localStorage.removeItem(refererKey); +} \ No newline at end of file