<commit_before>// @flow
import type {Manage, Action} from '../types'

const initManageState: Manage = {
	isLoading: false,
	isImageView: false,
	isImgLoaded: false,
	isDrawer: false,
	isMangaView: false,
	isDropdown: false,
	currentIllustId: null,
	userId: null,
	isModal: true,
	modalType: 'LOGIN',
}

type CloseState = {
	isImageView: bool,
	isDrawer: bool,
	isMangaView: bool,
	isModal: bool,
	isDropdown: bool
};

const closeState: CloseState = {
	isImageView: false,
	isDrawer: false,
	isMangaView: false,
	isModal: false,
	isDropdown: false,
}

function open(state: Manage, action: Action): $Shape<Manage> {
	switch (action.type) {
		case 'OPEN_IMAGE_VIEW':
			return {...state, isImageView: Boolean(state.currentIllustId)}
		case 'OPEN_MANGA_PREVIEW':
			return {...state, isMangaView: Boolean(state.currentIllustId)}
		case 'OPEN_MODAL':
			return {...state, ...closeState, isModal: true, modalType: action.modal}
		case 'OPEN_DROPDOWN':
			return {...state, ...closeState, isDropdown: true}
		case 'OPEN_DRAWER':
			return {...state, ...closeState, isDrawer: Boolean(action.id), userId: action.id}
		default:
			return state
	}
}

function close(state: Manage, action: Action): $Shape<Manage> {
	switch (action.type) {
		case 'CLOSE_IMAGE_VIEW':
			return {...state, isImageView: false}
		case 'CLOSE_MANGA_PREVIEW':
			return {...state, isMangaView: false}
		case 'CLOSE_ALL':
			return {...state, ...closeState}
		default:
			return {...state, ...closeState}
	}
}

export default function (state: Manage = initManageState, action: Action): $Shape<Manage> {
	if (/^OPEN/.test(action.type)) {
		return open(state, action)
	} else if (/^CLOSE/.test(action.type)) {
		return close(state, action)
	}
	switch (action.type) {
		case 'INIT':
			return {...state, ...closeState}
		case 'LOGOUT':
			return {...state, ...closeState, isModal: true, modalType: 'LOGIN'}
		case 'TOGGLE_DROPDOWN':
			return {...state, ...closeState, isDropdown: !state.isDropdown}
		case 'START_IMG_LOADING':
			return {...state, isImgLoaded: false}
		case 'SET_IMG_LOADED':
			return {...state, isImgLoaded: true}
		case 'SELECT_WORK':
			return {...state, currentIllustId: action.id}
		case 'START_LOADING':<commit_msg>Fix reducers at manage#open<commit_after>// @flow
import type {Manage, Action} from '../types'

const initManageState: Manage = {
	isLoading: false,
	isImageView: false,
	isImgLoaded: false,
	isDrawer: false,
	isMangaView: false,
	isDropdown: false,
	currentIllustId: null,
	userId: null,
	isModal: true,
	modalType: 'LOGIN',
}

type CloseState = {
	isImageView: bool,
	isDrawer: bool,
	isMangaView: bool,
	isModal: bool,
	isDropdown: bool
};

const closeState: CloseState = {
	isImageView: false,
	isDrawer: false,
	isMangaView: false,
	isModal: false,
	isDropdown: false,
}

function open(state: Manage, action: Action): $Shape<Manage> {
	switch (action.type) {
		case 'OPEN_IMAGE_VIEW':
			return {isImageView: Boolean(state.currentIllustId)}
		case 'OPEN_MANGA_PREVIEW':
			return {isMangaView: Boolean(state.currentIllustId)}
		case 'OPEN_MODAL':
			return {...closeState, isModal: true, modalType: action.modal}
		case 'OPEN_DROPDOWN':
			return {...closeState, isDropdown: true}
		case 'OPEN_DRAWER':
			return {...closeState, isDrawer: Boolean(action.id), userId: action.id}
		default:
			return state
	}
}

function close(state: Manage, action: Action): $Shape<Manage> {
	switch (action.type) {
		case 'CLOSE_IMAGE_VIEW':
			return {...state, isImageView: false}
		case 'CLOSE_MANGA_PREVIEW':
			return {...state, isMangaView: false}
		case 'CLOSE_ALL':
			return {...state, ...closeState}
		default:
			return {...state, ...closeState}
	}
}

export default function (state: Manage = initManageState, action: Action): $Shape<Manage> {
	if (/^OPEN/.test(action.type)) {
		return {...state, ...open(state, action)}
	} else if (/^CLOSE/.test(action.type)) {
		return close(state, action)
	}
	switch (action.type) {
		case 'INIT':
			return {...state, ...closeState}
		case 'LOGOUT':
			return {...state, ...closeState, isModal: true, modalType: 'LOGIN'}
		case 'TOGGLE_DROPDOWN':
			return {...state, ...closeState, isDropdown: !state.isDropdown}
		case 'START_IMG_LOADING':
			return {...state, isImgLoaded: false}
		case 'SET_IMG_LOADED':
			return {...state, isImgLoaded: true}
		case 'SELECT_WORK':
			return {...state, currentIllustId: action.id}
		case 'START_LOADING':
{'fraction_non_alphanumeric': 0.15377595254391968, 'fraction_numerical': 0.0, 'mean_word_length': 4.139507620164126, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4785664', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1574, 'n_words': 390}