...
 
Commits (2)
......@@ -54,6 +54,7 @@ type BookComponent {
componentType: String!
trackChangesEnabled: Boolean!
uploading: Boolean!
includeInTOC: Boolean!
}
input BookComponentInput {
......@@ -75,6 +76,7 @@ input UpdateBookComponentInput {
title: String
deleted: Boolean
lock: LockInput
includeInTOC: Boolean
uploading: Boolean
pagination: PaginationInput
workflowStages: [WorkFlowItemInput]
......@@ -102,6 +104,7 @@ extend type Mutation {
updateContent(input: UpdateBookComponentInput): BookComponent!
updateComponentType(input: UpdateBookComponentInput): BookComponent!
updateUploading(input: UpdateBookComponentInput): BookComponent!
toggleIncludeInTOC(input: UpdateBookComponentInput): BookComponent!
}
extend type Subscription {
......@@ -115,4 +118,5 @@ extend type Subscription {
bookComponentContentUpdated: BookComponent!
bookComponentTypeUpdated: BookComponent!
bookComponentUploadingUpdated: BookComponent!
bookComponentTOCToggled: BookComponent!
}
......@@ -36,6 +36,7 @@ const {
BOOK_COMPONENT_UPLOADING_UPDATED,
BOOK_COMPONENT_LOCK_UPDATED,
BOOK_COMPONENT_TYPE_UPDATED,
BOOK_COMPONENT_TOC_UPDATED,
} = require('./consts')
const { pubsubManager } = pubsweetServer
......@@ -241,7 +242,7 @@ const addBookComponents = async (_, { input }, ctx, info) => {
throw new Error(e)
}
}
// TODO: Pending implementation
const renameBookComponent = async (_, { input }, ctx) => {
const { id, title } = input
const pubsub = await pubsubManager.getPubsub()
......@@ -388,7 +389,7 @@ const updateWorkflowState = async (_, { input }, ctx) => {
}
}
// TODO: Pending implementation
const unlockBookComponent = async (_, { input }, ctx) => {
try {
const pubsub = await pubsubManager.getPubsub()
......@@ -413,7 +414,7 @@ const unlockBookComponent = async (_, { input }, ctx) => {
}
}
// TODO: Pending implementation
const lockBookComponent = async (_, { input }, ctx) => {
try {
const pubsub = await pubsubManager.getPubsub()
......@@ -447,7 +448,7 @@ const lockBookComponent = async (_, { input }, ctx) => {
}
}
// TODO: Pending implementation
const updateContent = async (_, { input }, ctx) => {
const { id, content, workflowStages, uploading } = input
const pubsub = await pubsubManager.getPubsub()
......@@ -594,6 +595,30 @@ const updateComponentType = async (_, { input }, ctx) => {
return updatedBookComponent
}
const toggleIncludeInTOC = async (_, { input }, ctx) => {
try {
const { id } = input
const pubsub = await pubsubManager.getPubsub()
const currentSate = await BookComponentState.query().where(
'bookComponentId',
id,
)
const up = await BookComponentState.query()
.patch({ includeInToc: !currentSate[0].includeInToc })
.findById(currentSate[0].id)
const updatedBookComponent = await BookComponent.findById(id)
pubsub.publish(BOOK_COMPONENT_TOC_UPDATED, {
bookComponentTOCToggled: updatedBookComponent,
})
return updatedBookComponent
} catch (e) {
logger.error(e)
throw new Error(e)
}
}
module.exports = {
Query: {
getBookComponent,
......@@ -613,10 +638,10 @@ module.exports = {
updateUploading,
updateTrackChanges,
updateComponentType,
toggleIncludeInTOC,
},
BookComponent: {
async title(bookComponent, _, ctx) {
// console.log('bokk', bookComponent)
let { title } = bookComponent
if (!title) {
const bookComponentTranslation = await BookComponentTranslation.query()
......@@ -631,11 +656,10 @@ module.exports = {
},
async bookTitle(bookComponent, _, ctx) {
const book = await Book.findById(bookComponent.bookId)
// console.log('book', book, bookComponent)
const bookTranslation = await BookTranslation.query()
.where('bookId', book.id)
.andWhere('languageIso', 'en')
// console.log('booktit', bookTranslation)
return bookTranslation[0].title
},
async nextBookComponent(bookComponent, _, ctx) {
......@@ -761,6 +785,11 @@ module.exports = {
)
return bookComponentState[0].workflowStages || null
},
async includeInTOC(bookComponent, _, ctx) {
const state = await bookComponent.getBookComponentState()
return state.includeInToc
},
},
Subscription: {
bookComponentAdded: {
......@@ -829,5 +858,11 @@ module.exports = {
return pubsub.asyncIterator(BOOK_COMPONENT_TYPE_UPDATED)
},
},
bookComponentTOCToggled: {
subscribe: async () => {
const pubsub = await pubsubManager.getPubsub()
return pubsub.asyncIterator(BOOK_COMPONENT_TOC_UPDATED)
},
},
},
}
......@@ -9,6 +9,7 @@ const BOOK_COMPONENT_CONTENT_UPDATED = 'BOOK_COMPONENT_CONTENT_UPDATED'
const BOOK_COMPONENT_UPLOADING_UPDATED = 'BOOK_COMPONENT_UPLOADING_UPDATED'
const BOOK_COMPONENT_LOCK_UPDATED = 'BOOK_COMPONENT_LOCK_UPDATED'
const BOOK_COMPONENT_TYPE_UPDATED = 'BOOK_COMPONENT_TYPE_UPDATED'
const BOOK_COMPONENT_TOC_UPDATED = 'BOOK_COMPONENT_TOC_UPDATED'
module.exports = {
BOOK_COMPONENT_ADDED,
......@@ -21,4 +22,5 @@ module.exports = {
BOOK_COMPONENT_UPLOADING_UPDATED,
BOOK_COMPONENT_LOCK_UPDATED,
BOOK_COMPONENT_TYPE_UPDATED,
BOOK_COMPONENT_TOC_UPDATED,
}
......@@ -49,7 +49,7 @@ const updateBookComponentOrder = async (
pubsub.publish(BOOK_COMPONENT_ORDER_UPDATED, {
bookComponentOrderUpdated: book,
})
console.log('reorder 1', book)
} else {
sourceDivision.bookComponents.splice(found, 1)
await Division.query().patchAndFetchById(sourceDivision.id, {
......@@ -78,12 +78,12 @@ const updateBookComponentOrder = async (
pubsub.publish(BOOK_COMPONENT_ORDER_UPDATED, {
bookComponentOrderUpdated: book,
})
console.log('reorder 2', book)
}
return Book.findById(bookComponent.bookId)
},
)
console.log('res', bookTransaction)
return bookTransaction
}
......
......@@ -35,7 +35,7 @@ const getTemplates = async (_, { ascending, sortKey }, ctx) => {
}
const getTemplate = async (_, { id }, ctx) => {
const template = await Template.findById(id)
console.log('template', template)
return template
}
......@@ -188,7 +188,7 @@ const createTemplate = async (_, { input }, ctx) => {
// TODO:
const updateTemplate = async (_, { input }, ctx) => {
console.log('input', input)
const {
id,
name,
......@@ -458,15 +458,15 @@ module.exports = {
},
Template: {
async files(template, _, ctx) {
console.log('template1', template)
const files = await template.getFiles()
console.log('files', files)
return files
},
async thumbnail(template, _, ctx) {
console.log('template2', template)
const thumbnail = await template.getThumbnail()
console.log('thum', thumbnail)
return thumbnail
},
},
......
......@@ -78,6 +78,7 @@ export class BookBuilder extends React.Component {
addBookComponents,
currentUser,
deleteBookComponent,
toggleIncludeInTOC,
updateApplicationParameters,
updateBookComponentPagination,
updateBookComponentOrder,
......@@ -152,6 +153,7 @@ export class BookBuilder extends React.Component {
addBookComponent={addBookComponent}
applicationParameter={applicationParameter}
onWorkflowUpdate={onWorkflowUpdate}
toggleIncludeInTOC={toggleIncludeInTOC}
addBookComponents={addBookComponents}
setState={setState}
onWarning={onWarning}
......
......@@ -36,6 +36,8 @@ import {
updateBookMetadataMutation,
bookMetadataSubscription,
bookRenamedSubscription,
toggleIncludeInTOCMutation,
bookComponentIncludeInTOCSubscription,
} from './queries'
const mapper = {
......@@ -53,6 +55,7 @@ const mapper = {
titleChangeSubscription,
productionEditorChangeSubscription,
componentTypeChangeSubscription,
bookComponentIncludeInTOCSubscription,
addTeamMemberSubscription,
updateBookMetadataMutation,
bookMetadataSubscription,
......@@ -60,6 +63,7 @@ const mapper = {
unlockBookComponentMutation,
createBookComponentsMutation,
deleteBookComponentMutation,
toggleIncludeInTOCMutation,
updateBookComponentPaginationMutation,
updatedBookComponentOrderMutation,
updateBookComponentWorkflowStateMutation,
......@@ -78,6 +82,7 @@ const mapProps = args => ({
addBookComponent: args.createBookComponentMutation.addBookComponent,
addBookComponents: args.createBookComponentsMutation.addBookComponents,
deleteBookComponent: args.deleteBookComponentMutation.deleteBookComponent,
toggleIncludeInTOC: args.toggleIncludeInTOCMutation.toggleIncludeInTOC,
updateBookComponentPagination:
args.updateBookComponentPaginationMutation.updateBookComponentPagination,
updateBookComponentOrder:
......@@ -274,6 +279,7 @@ const Connected = props => {
addBookComponent,
addBookComponents,
deleteBookComponent,
toggleIncludeInTOC,
updateBookComponentPagination,
updateBookComponentOrder,
updateComponentType,
......@@ -301,6 +307,7 @@ const Connected = props => {
addBookComponents={addBookComponents}
applicationParameter={applicationParameter}
state={state}
toggleIncludeInTOC={toggleIncludeInTOC}
setState={setState}
onTeamManager={onTeamManager}
onError={onError}
......
......@@ -116,7 +116,6 @@ const orderChangeSubscription = props => {
const { refetch } = getBookQuery
const { pauseUpdates } = statefull
const triggerRefetch = () => {
console.log('reorder sub')
if (pauseUpdates) return
refetch()
}
......@@ -138,7 +137,13 @@ const COMPONENT_TYPE_UPDATED_SUBSCRIPTION = gql`
}
}
`
const INCLUDE_IN_TOC_UPDATED_SUBSCRIPTION = gql`
subscription IncludeInTOCUpdated {
bookComponentTOCToggled {
id
}
}
`
const componentTypeChangeSubscription = props => {
const { render, getBookQuery, statefull } = props
const { pauseUpdates } = statefull
......@@ -158,6 +163,25 @@ const componentTypeChangeSubscription = props => {
)
}
const bookComponentIncludeInTOCSubscription = props => {
const { render, getBookQuery, statefull } = props
const { pauseUpdates } = statefull
const { refetch } = getBookQuery
const triggerRefetch = () => {
if (pauseUpdates) return
refetch()
}
return (
<Subscription
onSubscriptionData={triggerRefetch}
subscription={INCLUDE_IN_TOC_UPDATED_SUBSCRIPTION}
>
{render}
</Subscription>
)
}
const bookComponentAddedSubscription = props => {
const { render, getBookQuery, getBookBuilderRulesQuery, statefull } = props
const { pauseUpdates } = statefull
......@@ -355,4 +379,5 @@ export {
componentTypeChangeSubscription,
addTeamMemberSubscription,
bookMetadataSubscription,
bookComponentIncludeInTOCSubscription,
}
......@@ -25,6 +25,7 @@ const GET_BOOK = gql`
divisionId
title
bookId
includeInTOC
# hasContent
componentTypeOrder
pagination {
......
......@@ -4,6 +4,7 @@ export { default as getBookTeamsQuery } from './getBookTeams'
export { default as createBookComponentMutation } from './createBookComponent'
export { default as createBookComponentsMutation } from './createBookComponents'
export { default as deleteBookComponentMutation } from './deleteBookComponent'
export { default as toggleIncludeInTOCMutation } from './toggleIncludeInTOC'
export {
default as updateBookComponentPaginationMutation,
} from './updatePagination'
......@@ -27,6 +28,7 @@ export {
addTeamMemberSubscription,
bookMetadataSubscription,
bookRenamedSubscription,
bookComponentIncludeInTOCSubscription,
} from './bookBuilderSubscriptions'
export { default as findUserMutation } from './findUsers'
export { default as updateTeamMutation } from './updateTeam'
......
import React from 'react'
import { Mutation } from 'react-apollo'
import gql from 'graphql-tag'
const TOGGLE_INCLUDE_IN_TOC = gql`
mutation ToggleIncludeInTOC($input: UpdateBookComponentInput!) {
toggleIncludeInTOC(input: $input) {
id
}
}
`
const toggleIncludeInTOCMutation = props => {
const { render } = props
return (
<Mutation mutation={TOGGLE_INCLUDE_IN_TOC}>
{(toggleIncludeInTOC, toggleIncludeInTOCResult) =>
render({ toggleIncludeInTOC, toggleIncludeInTOCResult })
}
</Mutation>
)
}
export default toggleIncludeInTOCMutation
......@@ -18,7 +18,7 @@ const Container = styled.div`
border-left: ${({ noBorder }) => (noBorder.left ? 0 : '')};
`
const AlignmentBox = ({ active, id, noBorder, onClick }) => {
console.log('act', active)
return (
<Container
active={active}
......
......@@ -25,7 +25,7 @@ const AlignmentTool = ({ data, onClickAlignmentBox, componentType }) => {
}
const leftData = find(data, { id: 'left' })
const rightData = find(data, { id: 'right' })
console.log('data', data)
const noBorderRight = { right: true }
const noBorderLeft = { left: true }
......
......@@ -8,6 +8,7 @@ import BookComponentActions from './BookComponentActions'
import ComponentTypeMenu from './ComponetTypeMenu'
import SecondRow from './SecondRow'
import FirstRow from './FirstRow'
import { ButtonWithoutLabel } from './Button'
// import {
// bookComponentSource,
// bookComponentTarget,
......@@ -16,6 +17,27 @@ import FirstRow from './FirstRow'
// itemTypes,
// } from '../../dnd'
const StyledButton = styled(ButtonWithoutLabel)`
svg {
#Line {
visibility: ${({ includeInTOC }) =>
includeInTOC ? 'visible' : 'hidden'};
}
#Line_2 {
visibility: ${({ includeInTOC }) =>
includeInTOC ? 'visible' : 'hidden'};
}
}
&:hover {
#Line {
stroke: ${({ includeInTOC }) => (includeInTOC ? th('colorPrimary') : '')};
}
#Line_2 {
stroke: ${({ includeInTOC }) => (includeInTOC ? 'white' : '')};
}
}
`
const BookComponentContainer = styled.div`
display: flex;
flex-direction: column;
......@@ -160,6 +182,7 @@ const BookComponent = ({
provided,
bookId,
onWarning,
includeInTOC,
connectDragSource,
connectDropTarget,
applicationParameter,
......@@ -189,6 +212,7 @@ const BookComponent = ({
uploading,
updatePagination,
updateWorkflowState,
toggleIncludeInTOC,
updateBookComponentContent,
updateComponentType,
updateApplicationParameters,
......@@ -204,6 +228,17 @@ const BookComponent = ({
})
}
const onToggleIncludeInTOC = id => {
toggleIncludeInTOC({
variables: {
input: {
id,
},
},
})
}
const onAddComponentType = value => {
updateApplicationParameters({
variables: {
......@@ -259,6 +294,42 @@ const BookComponent = ({
/>
</svg>
)
const tocIcon = (
<svg
width="38"
height="22"
viewBox="0 0 38 22"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g id="TOC-icon">
<path
id="TOC"
d="M11.1014 4.616L10.9034 5.984H7.86142V17H6.18742V5.984H3.05542V4.616H11.1014ZM16.2086 4.382C17.6846 4.382 18.8426 4.928 19.6826 6.02C20.5346 7.1 20.9606 8.696 20.9606 10.808C20.9606 12.884 20.5406 14.474 19.7006 15.578C18.8606 16.682 17.6966 17.234 16.2086 17.234C14.7326 17.234 13.5686 16.694 12.7166 15.614C11.8766 14.522 11.4566 12.926 11.4566 10.826C11.4566 9.446 11.6486 8.276 12.0326 7.316C12.4286 6.344 12.9806 5.612 13.6886 5.12C14.4086 4.628 15.2486 4.382 16.2086 4.382ZM16.2086 5.714C14.2166 5.714 13.2206 7.418 13.2206 10.826C13.2206 14.198 14.2166 15.884 16.2086 15.884C17.1926 15.884 17.9366 15.482 18.4406 14.678C18.9446 13.874 19.1966 12.584 19.1966 10.808C19.1966 9.044 18.9386 7.754 18.4226 6.938C17.9186 6.122 17.1806 5.714 16.2086 5.714ZM27.4934 4.382C28.1414 4.382 28.7054 4.484 29.1854 4.688C29.6654 4.88 30.1394 5.186 30.6074 5.606L29.7434 6.614C29.3954 6.314 29.0474 6.092 28.6994 5.948C28.3634 5.804 27.9914 5.732 27.5834 5.732C26.6474 5.732 25.9034 6.134 25.3514 6.938C24.7994 7.73 24.5234 9.014 24.5234 10.79C24.5234 12.518 24.7994 13.796 25.3514 14.624C25.9034 15.44 26.6474 15.848 27.5834 15.848C28.0514 15.848 28.4534 15.764 28.7894 15.596C29.1254 15.428 29.4914 15.182 29.8874 14.858L30.7334 15.848C29.8334 16.772 28.7534 17.234 27.4934 17.234C26.5694 17.234 25.7474 16.994 25.0274 16.514C24.3194 16.034 23.7614 15.314 23.3534 14.354C22.9574 13.382 22.7594 12.194 22.7594 10.79C22.7594 9.398 22.9634 8.222 23.3714 7.262C23.7914 6.302 24.3554 5.582 25.0634 5.102C25.7834 4.622 26.5934 4.382 27.4934 4.382Z"
fill="#BDBDBD"
/>
<line
id="Line"
y1="-1"
x2="29.7664"
y2="-1"
transform="matrix(0.984144 -0.177373 0.0507775 0.99871 3.17969 14.5656)"
stroke="#BDBDBD"
strokeWidth="2"
/>
<line
id="Line_2"
y1="-1"
x2="34.7275"
y2="-1"
transform="matrix(0.984144 -0.177373 0.0507775 0.99871 3 16.1597)"
stroke="white"
strokeWidth="2"
/>
</g>
</svg>
)
const goToEditor = () => {
history.push(`/books/${bookId}/bookComponents/${id}`)
}
......@@ -285,6 +356,14 @@ const BookComponent = ({
<ButtonWithoutLabel onClick={goToEditor} icon={previewIcon} />
)} */}
</ActionsLeft>
<StyledButton
icon={tocIcon}
includeInTOC={includeInTOC}
onClick={e => {
e.preventDefault()
onToggleIncludeInTOC(id)
}}
/>
<BookComponentTitle
applicationParameter={applicationParameter}
bookComponentId={id}
......
......@@ -169,6 +169,7 @@ class Division extends React.Component {
divisionId,
onWarning,
showModal,
toggleIncludeInTOC,
onWorkflowUpdate,
onAdminUnlock,
showModalToggle,
......@@ -190,6 +191,7 @@ class Division extends React.Component {
bookId,
lock,
divisionId,
includeInTOC,
componentTypeOrder,
hasContent,
title,
......@@ -208,6 +210,7 @@ class Division extends React.Component {
bookId={bookId}
onAdminUnlock={onAdminUnlock}
onWorkflowUpdate={onWorkflowUpdate}
toggleIncludeInTOC={toggleIncludeInTOC}
currentUser={currentUser}
canDrag={reorderingAllowed}
componentType={componentType}
......@@ -223,14 +226,13 @@ class Division extends React.Component {
key={id}
lock={lock}
no={i}
onEndDrag={() => console.log('hello')}
onMove={() => console.log('hello')}
outerContainer={outerContainer}
pagination={pagination}
provided={provided}
remove={this.onRemove}
rules={rules}
showModal={showModal}
includeInTOC={includeInTOC}
showModalToggle={showModalToggle}
title={title}
trackChangesEnabled={trackChangesEnabled}
......
......@@ -212,6 +212,7 @@ class DivisionsArea extends Component {
onAdminUnlock,
updateBookComponentContent,
updateBookComponentUploading,
toggleIncludeInTOC,
outerContainer,
showModal,
showModalToggle,
......@@ -220,10 +221,11 @@ class DivisionsArea extends Component {
uploading,
rules,
} = this.props
const { divisions } = this.state
const { canReorderBookComponent } = rules
const renderDivision = (reorderingAllowed, bookComponents, label, id) => {
return (
<Division
add={addBookComponent}
......@@ -233,6 +235,7 @@ class DivisionsArea extends Component {
bookId={bookId}
currentUser={currentUser}
deleteBookComponent={deleteBookComponent}
toggleIncludeInTOC={toggleIncludeInTOC}
divisionId={id}
history={history}
key={id}
......
......@@ -88,7 +88,7 @@ const UploadFileButton = ({
})
})
.catch(error => {
console.log('error', error)
updateBookComponentUploading({
variables: {
input: {
......
......@@ -134,11 +134,11 @@ class UploadFilesButton extends React.Component {
})
})
.catch(error => {
console.log('error', error)
console.error('error', error)
const stuckedBookComponents = filter(addBookComponents, {
uploading: true,
})
console.log('str', stuckedBookComponents)
console.error('str', stuckedBookComponents)
Promise.all(
map(stuckedBookComponents, async bookComponent => {
update({
......@@ -160,7 +160,7 @@ class UploadFilesButton extends React.Component {
})
.catch(async error => {
self.setState({ counter: 0, uploading: false })
console.log('error', error)
console.error('error', error)
})
})
}
......
......@@ -129,7 +129,7 @@ class MetadataModal extends React.Component {
renderBody() {
const { data, hideModal } = this.props
const { onConfirm, book } = data
console.log('props', this.props)
return (
<div>
<Formik
......
......@@ -132,7 +132,7 @@ const Book = props => {
onArchiveBook,
} = props
const { authors, isPublished, archived } = book
console.log('book', book)
const { canRenameBooks, canDeleteBooks, canArchiveBooks } = bookRule
return (
......
......@@ -253,7 +253,7 @@ class AddBookModal extends React.Component {
render() {
const { isOpen, hideModal } = this.props
console.log('props', this.props)
const body = this.renderBody()
return (
......
......@@ -63,7 +63,7 @@ class BookComponentState extends Base {
},
trackChangesEnabled: booleanDefaultFalse,
uploading: booleanDefaultFalse,
includeInTOC: booleanDefaultFalse,
includeInToc: booleanDefaultFalse,
runningHeadersRight: string,
runningHeadersLeft: string,
// left loose on purpose to allow for configurability
......
......@@ -2,5 +2,5 @@ exports.up = async knex =>
knex.schema.table('book_component_state', table => {
table.string('runningHeadersRight')
table.string('runningHeadersLeft')
table.boolean('includeInTOC')
table.boolean('includeInToc').defaultTo(false)
})
......@@ -16,7 +16,6 @@ class UploadFilesButton extends React.Component {
const { updateFilesList, setFieldValue, setFieldTouched } = this.props
const originalFiles = event.target.files
console.log('orig', originalFiles)
updateFilesList(originalFiles, setFieldValue, setFieldTouched)
}
......
......@@ -22,7 +22,6 @@ class UploadThumbnail extends React.Component {
const { updateThumbnail, setFieldValue, setFieldTouched } = this.props
const originalFiles = event.target.files
console.log('orig', originalFiles)
updateThumbnail(originalFiles[0], setFieldValue, setFieldTouched)
}
......
......@@ -18,7 +18,7 @@ const mapProps = args => {
const Composed = adopt(mapper, mapProps)
const Connected = props => {
console.log('props', props)
// const { data, isOpen } = props
const { data, isOpen, hideModal } = props
const { templateId } = data
......
......@@ -36,8 +36,6 @@ const Input = styled.input`
outline: 0;
border-bottom: 1px dashed
${({ errors, errorId, touched }) => {
console.log('asdfasdf', errorId)
console.log('asdfasdf', errors)
return errors[errorId] && touched[errorId]
? th('colorError')
: th('colorText')
......@@ -202,7 +200,7 @@ const Image = styled.img`
class TemplateModal extends React.Component {
constructor(props) {
super(props)
console.log('props in tem', props)
const { data, template } = props
const { mode } = data
this.updateFileList = this.updateFileList.bind(this)
......@@ -243,7 +241,7 @@ class TemplateModal extends React.Component {
for (let i = 0; i < fileList.length; i += 1) {
selectedFiles.push(fileList.item(i))
}
console.log('selectedFIles', selectedFiles)
this.setState({ files: selectedFiles })
setFieldValue('files', selectedFiles)
setFieldTouched('files', true)
......@@ -257,7 +255,7 @@ class TemplateModal extends React.Component {
const { thumbnail, mode } = this.state
const reader = new FileReader()
reader.readAsDataURL(file)
console.log('thumb', thumbnail)
reader.onloadend = function(e) {
let newState
if (mode === 'update') {
......@@ -281,13 +279,12 @@ class TemplateModal extends React.Component {
const tempFiles = cloneDeep(files)
const tempDeleted = cloneDeep(deleteFiles)
const fileIndex = findIndex(tempFiles, { name: filename })
if (mode === 'update' && tempFiles[fileIndex].id) {
const { id } = tempFiles[fileIndex]
tempDeleted.push(id)
files.splice(fileIndex, 1)
newState = {
deleteFiles: tempDeleted,
files,
......@@ -298,7 +295,6 @@ class TemplateModal extends React.Component {
files,
}
}
setFieldValue('files', files)
this.setState(newState)
......@@ -385,14 +381,14 @@ class TemplateModal extends React.Component {
trimSize,
}
}
return (
<Formik
initialValues={initialValues}
onSubmit={(values, { setSubmitting }) => {
const { name, author, trimSize, files, thumbnail, target } = values
const { deleteFiles, deleteThumbnail, mode } = this.state
let data
if (mode === 'create') {
data = {
......@@ -415,7 +411,7 @@ class TemplateModal extends React.Component {
target: target ? target.value : undefined,
}
}
onConfirm(data)
setSubmitting(false)
}}
......@@ -498,7 +494,9 @@ class TemplateModal extends React.Component {
errorId="name"
errors={errors}
touched={touched}
onKeyPress={(e) => { e.key === 'Enter' && e.preventDefault(); }}
onKeyPress={e => {
e.key === 'Enter' && e.preventDefault()
}}
name="name"
onBlur={handleBlur}
onChange={handleChange}
......@@ -516,7 +514,9 @@ class TemplateModal extends React.Component {
errorId="author"
errors={errors}
touched={touched}
onKeyPress={(e) => { e.key === 'Enter' && e.preventDefault(); }}
onKeyPress={e => {
e.key === 'Enter' && e.preventDefault()
}}
name="author"
onBlur={handleBlur}
onChange={handleChange}
......@@ -533,7 +533,9 @@ class TemplateModal extends React.Component {
<Input
errorId="trimSize"
touched={touched}
onKeyPress={(e) => { e.key === 'Enter' && e.preventDefault(); }}
onKeyPress={e => {
e.key === 'Enter' && e.preventDefault()
}}
errors={errors}
name="trimSize"
onBlur={handleBlur}
......@@ -591,7 +593,7 @@ class TemplateModal extends React.Component {
const { isOpen, hideModal, data } = this.props
const { headerText } = data
const body = this.renderBody()
return (
<FormModal
headerText={headerText}
......