refactor Create.js -> generateUrlCode.js && simply fix in FormGenerator.js -> AbstractUtils

develop
TBS093A 2020-08-12 15:11:15 +02:00
parent 03f4d8065b
commit 8396f1918f
3 changed files with 36 additions and 30 deletions

View File

@ -0,0 +1,22 @@
export const generateUrlCode = ( type ) => {
let code = 'op?' + type + '='
let hash = [
'!', '@', '#', '$', '%', '^', '&', '*',
'Q', 'W', 'X', 'S', 'q', 'w', 'x', 's'
]
code += hash[ randomInt(7, 14) ]
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(0, 7) ]
+ hash[ randomInt(0, 7) ]
+ hash[ randomInt(0, 7) ]
+ randomInt(0, 9)
+ randomInt(0, 9)
+ randomInt(0, 9)
return code
}
const randomInt = (min, max) => {
return min + Math.floor((max - min) * Math.random())
}

View File

@ -40,6 +40,7 @@ const FormGenerator = ({
* { * {
* type: 'text', * type: 'text',
* name: 'name', * name: 'name',
* endpoint: 'Album',
* ref: React.createRef() * ref: React.createRef()
* } } input - basic text input * } } input - basic text input
*/ */
@ -50,7 +51,7 @@ const TextInputGenerator = ({
<div> <div>
{ input.name + ':' } { input.name + ':' }
<input <input
id={ input.name + 'Input' } id={ input.name + input.endpoint + 'Input' }
autoComplete='off' autoComplete='off'
ref={ input.ref } ref={ input.ref }
/> />
@ -64,7 +65,8 @@ const TextInputGenerator = ({
* { * {
* type: 'file', * type: 'file',
* name: 'name', * name: 'name',
* fileType: 'image', * endpoint: 'Album',
* fileType: 'image' or 'audio',
* dropInfo: dropInfo, setDropInfo: setDropInfo(), #useState * dropInfo: dropInfo, setDropInfo: setDropInfo(), #useState
* file: file, setFile: setFile() #useState * file: file, setFile: setFile() #useState
* } } input - * } } input -
@ -112,9 +114,10 @@ const UploadInputGenerator = ({
</pre> </pre>
<input <input
style={ { marginTop: '-55px' } } style={ { marginTop: '-55px' } }
id={ input.name + 'Input' } id={ input.name + input.endpoint + 'Input' }
className='uploadInput' className='uploadInput'
type='file' type='file'
accept={ input.fileType + '/*' }
autoComplete='off' autoComplete='off'
onChange={ event => onLoadFile( event ) } onChange={ event => onLoadFile( event ) }
/> />

View File

@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { createAlbum } from '../../../../../../stores/album/duck/operations' import { createAlbum } from '../../../../../../stores/album/duck/operations'
import { generateUrlCode } from '../../../../../generateUrlCode'
import FormGenerator from '../Abstract Utils/FormGenerator' import FormGenerator from '../Abstract Utils/FormGenerator'
@ -23,17 +24,20 @@ const AlbumCreate = ({
let inputList = [ let inputList = [
{ {
type: 'text', type: 'text',
name: 'titleAlbum', name: 'title',
endpoint: 'Album',
ref: titleInput ref: titleInput
}, },
{ {
type: 'text', type: 'text',
name: 'descriptionAlbum', name: 'description',
endpoint: 'Album',
ref: descriptionInput ref: descriptionInput
}, },
{ {
type: 'file', type: 'file',
name: 'imageAlbum', name: 'image',
endpoint: 'Album',
fileType: 'image', fileType: 'image',
dropInfo: imageInfo, dropInfo: imageInfo,
setDropInfo: setImageInfo, setDropInfo: setImageInfo,
@ -59,7 +63,7 @@ const AlbumCreate = ({
title: title, title: title,
description: description, description: description,
image: image, image: image,
url_code: generateUrlCode(), url_code: generateUrlCode( 'album' ),
} }
await createAlbum( await createAlbum(
album, album,
@ -68,29 +72,6 @@ const AlbumCreate = ({
setMessage( response['info'] + '\n' ) setMessage( response['info'] + '\n' )
}) })
} }
const generateUrlCode = () => {
let code = 'op?album='
let hash = [
'!', '@', '#', '$', '%', '^', '&', '*',
'Q', 'W', 'X', 'S', 'q', 'w', 'x', 's'
]
code +=
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(0, 7) ]
+ hash[ randomInt(0, 7) ]
+ hash[ randomInt(0, 7) ]
+ randomInt(0, 9)
+ randomInt(0, 9)
+ randomInt(0, 9)
return code
}
const randomInt = (min, max) => {
return min + Math.floor((max - min) * Math.random())
}
useEffect( useEffect(
() => { () => {