Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { setWith, TypedAction, TypedReducer } from 'redoodle';
import { User } from '../../modules/api/jophiel/user';
export interface SessionState {
isLoggedIn: boolean;
token?: string;
user?: User;
}
// Somehow redux-persist won't work after dispatching DelSession if the next state is an empty object...
export const INITIAL_STATE: SessionState = { isLoggedIn: false };
export const PutToken = TypedAction.define('session/PUT_TOKEN')();
export const PutUser = TypedAction.define('session/PUT_USER')();
export const DelSession = TypedAction.defineWithoutPayload('session/DEL')();
const createSessionReducer = () => {
const builder = TypedReducer.builder();
builder.withHandler(PutToken.TYPE, (state, payload) => ({
isLoggedIn: true,
token: payload,
}));
builder.withHandler(PutUser.TYPE, (state, payload) => setWith(state, { user: payload }));
builder.withHandler(DelSession.TYPE, () => INITIAL_STATE);
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
};
import { setWith, TypedAction, TypedReducer } from 'redoodle';
import { Contest } from '../../../../modules/api/uriel/contest';
export interface ContestState {
value?: Contest;
isEditing?: boolean;
}
export const INITIAL_STATE: ContestState = {};
export const PutContest = TypedAction.define('uriel/contest/PUT')();
export const DelContest = TypedAction.defineWithoutPayload('uriel/contest/DEL')();
export const EditContest = TypedAction.define('uriel/contest/EDIT')();
function createContestReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutContest.TYPE, (state, payload) => setWith(state, { value: payload }));
builder.withHandler(DelContest.TYPE, () => ({ value: undefined }));
builder.withHandler(EditContest.TYPE, (state, payload) => setWith(state, { isEditing: payload }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const contestReducer = createContestReducer();
import { setWith, TypedAction, TypedReducer } from 'redoodle';
import { Contest } from '../../../../modules/api/uriel/contest';
export interface ContestState {
value?: Contest;
isEditing?: boolean;
}
export const INITIAL_STATE: ContestState = {};
export const PutContest = TypedAction.define('uriel/contest/PUT')();
export const DelContest = TypedAction.defineWithoutPayload('uriel/contest/DEL')();
export const EditContest = TypedAction.define('uriel/contest/EDIT')();
function createContestReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutContest.TYPE, (state, payload) => setWith(state, { value: payload }));
builder.withHandler(DelContest.TYPE, () => ({ value: undefined }));
builder.withHandler(EditContest.TYPE, (state, payload) => setWith(state, { isEditing: payload }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const contestReducer = createContestReducer();
import { INote, NoteId } from '@src/model';
import { TypedAction } from 'redoodle';
export const NotesLoaded = TypedAction.define('NOTES_LOADED')<{
notes: INote[],
}>();
export const NoteAdded = TypedAction.define('NOTE_ADDED')<{
noteId: NoteId;
}>();
export const NoteDeleted = TypedAction.define('NOTE_DELETED')<{
noteId: NoteId;
}>();
export const NoteSaved = TypedAction.define('NOTE_SAVED')<{
noteId: NoteId;
content: string;
}>();
export const NoteSelected = TypedAction.define('NOTE_SELECTED')<{
noteId: NoteId;
}>();
import { TypedAction, TypedReducer } from 'redoodle';
import { JophielRole } from 'modules/api/jophiel/my';
export interface RoleState {
value: JophielRole;
}
export const INITIAL_STATE: RoleState = {
value: JophielRole.Guest,
};
export const PutRole = TypedAction.define('jophiel/role/PUT')();
function createRoleReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutRole.TYPE, (state, payload) => ({ value: payload }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const roleReducer = createRoleReducer();
import { TypedAction, TypedReducer } from 'redoodle';
import { JophielRole } from '../../../modules/api/jophiel/my';
export interface RoleState {
value: JophielRole;
}
export const INITIAL_STATE: RoleState = {
value: JophielRole.Guest,
};
export const PutRole = TypedAction.define('jophiel/role/PUT')();
function createRoleReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutRole.TYPE, (state, payload) => ({ value: payload }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const roleReducer = createRoleReducer();
import { TypedAction, TypedReducer } from 'redoodle';
export interface Breadcrumb {
link: string;
title: string;
}
export interface BreadcrumbsState {
values: Breadcrumb[];
}
export const INITIAL_STATE: BreadcrumbsState = { values: [] };
export const PushBreadcrumb = TypedAction.define('breadcrumbs/PUSH')();
export const PopBreadcrumb = TypedAction.define('breadcrumbs/POP')<{
link: string;
}>();
const cleanLink = link => {
return link.replace(/\/+$/, '');
};
const createBreadcrumbsReducer = () => {
const builder = TypedReducer.builder();
builder.withHandler(PushBreadcrumb.TYPE, (state, { link, ...rest }) => ({
values: [...state.values, { link: cleanLink(link), ...rest }],
}));
builder.withHandler(PopBreadcrumb.TYPE, (state, payload) => ({
values: state.values.filter(b => b.link !== cleanLink(payload.link)),
}));
import { TypedAction } from 'redoodle';
export const NotesLoaded = TypedAction.define('NOTES_LOADED')<{
notes: INote[],
}>();
export const NoteAdded = TypedAction.define('NOTE_ADDED')<{
noteId: NoteId;
}>();
export const NoteDeleted = TypedAction.define('NOTE_DELETED')<{
noteId: NoteId;
}>();
export const NoteSaved = TypedAction.define('NOTE_SAVED')<{
noteId: NoteId;
content: string;
}>();
export const NoteSelected = TypedAction.define('NOTE_SELECTED')<{
noteId: NoteId;
}>();
import { TypedAction, TypedReducer } from 'redoodle';
export interface ProfileState {
userJid?: string;
username?: string;
}
export const INITIAL_STATE: ProfileState = {};
export const PutUser = TypedAction.define('jophiel/profile/PUT')<{
userJid: string;
username: string;
}>();
export const DelUser = TypedAction.defineWithoutPayload('jophiel/profile/DEL')();
function createProfileReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutUser.TYPE, (state, payload) => payload);
builder.withHandler(DelUser.TYPE, () => ({ userJid: undefined, username: undefined }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const profileReducer = createProfileReducer();
import { setWith, TypedAction, TypedReducer } from 'redoodle';
export interface WebPrefsState {
statementLanguage: string;
gradingLanguage: string;
}
export const INITIAL_STATE: WebPrefsState = { statementLanguage: 'id', gradingLanguage: 'Cpp11' };
export const PutStatementLanguage = TypedAction.define('webPrefs/PUT_STATEMENT_LANGUAGE')();
export const PutGradingLanguage = TypedAction.define('webPrefs/PUT_GRADING_LANGUAGE')();
function createWebPrefsReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutStatementLanguage.TYPE, (state, statementLanguage) => setWith(state, { statementLanguage }));
builder.withHandler(PutGradingLanguage.TYPE, (state, gradingLanguage) => setWith(state, { gradingLanguage }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const webPrefsReducer = createWebPrefsReducer();