create abstract string mapping
parent
5ff1a6ae06
commit
3fa6d9cfbf
|
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
export const mapRowsToString = (objects, type, fields) => {
|
||||||
|
let list = '.' + type + '\n'
|
||||||
|
for (let i = 0; i < objects.length; i++) {
|
||||||
|
if (i !== objects.length - 1) {
|
||||||
|
for (let j = 0; j < fields.length; j++) {
|
||||||
|
if ( j === 0 ) {
|
||||||
|
list += '├── ' + objects[i][ fields[j] ] + '\n'
|
||||||
|
} else if (j !== fields.length - 1) {
|
||||||
|
list += '│ ├── ' + fields[j] + ': ' + objects[i][ fields[j] ] + '\n'
|
||||||
|
} else {
|
||||||
|
list += '│ └── ' + fields[j] + ': ' + objects[i][ fields[j] ] + '\n'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let j = 0; j < fields.length; j++) {
|
||||||
|
if ( j === 0 ) {
|
||||||
|
list += '└── ' + objects[i][ fields[j] ] + '\n'
|
||||||
|
} else if (j !== fields.length - 1) {
|
||||||
|
list += ' ├── ' + fields[j] + ': ' + objects[i][ fields[j] ] + '\n'
|
||||||
|
} else {
|
||||||
|
list += ' └── ' + fields[j] + ': ' + objects[i][ fields[j] ] + '\n'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
@ -50,10 +50,8 @@ export const ResetComponentWithoutInputs = ({
|
||||||
activateConsoleInput
|
activateConsoleInput
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const [oneRequest, setOneRequest] = useState(false)
|
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
if (componentVisible && oneRequest === false) {
|
if (componentVisible) {
|
||||||
fetchAction().then(response => {
|
fetchAction().then(response => {
|
||||||
setMessage(
|
setMessage(
|
||||||
mapObjectToString(
|
mapObjectToString(
|
||||||
|
|
@ -61,13 +59,10 @@ export const ResetComponentWithoutInputs = ({
|
||||||
) + response['info'] + '\n'
|
) + response['info'] + '\n'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
setOneRequest( true )
|
if (message !== '') {
|
||||||
} else {
|
resetState()
|
||||||
activateConsoleInput()
|
activateConsoleInput()
|
||||||
}
|
}
|
||||||
if (message !== '') {
|
|
||||||
resetState()
|
|
||||||
setOneRequest( false )
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState } 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'
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
|
|
||||||
import { getAllAlbum } from '../../../../../../stores/album/duck/operations'
|
import { getAllAlbum } from '../../../../../../stores/album/duck/operations'
|
||||||
|
import { ResetComponentWithoutInputs } from '../Abstract Utils/ResetComponent'
|
||||||
|
import { mapRowsToString } from '../Abstract Utils/MapRowsToString'
|
||||||
|
|
||||||
const AlbumGetAll = ({
|
const AlbumGetAll = ({
|
||||||
album,
|
album,
|
||||||
|
|
@ -13,50 +14,34 @@ const AlbumGetAll = ({
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const [message, setMessage] = useState('')
|
const [message, setMessage] = useState('')
|
||||||
const [oneRequest, setOne] = useState(false)
|
|
||||||
|
|
||||||
useEffect(
|
const resetState = () => {
|
||||||
() => {
|
setConsoleHistory(consoleHistory + message)
|
||||||
if (componentVisible && oneRequest === false) {
|
setComponentVisible(false)
|
||||||
getAllAlbum().then(response => {
|
setMessage('')
|
||||||
setMessage(
|
}
|
||||||
mapAlbumsToString(
|
|
||||||
response['response']
|
|
||||||
) + response['info'] + '\n'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
setOne( true )
|
|
||||||
} else {
|
|
||||||
activateConsoleInput()
|
|
||||||
}
|
|
||||||
if (message !== '') {
|
|
||||||
setConsoleHistory(consoleHistory + message)
|
|
||||||
setComponentVisible(false)
|
|
||||||
setOne(!oneRequest)
|
|
||||||
setMessage('')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const mapAlbumsToString = (albums) => {
|
const mapAlbumsToString = (albums) => {
|
||||||
let list = '.albums\n'
|
let mapFields = [
|
||||||
for (let i = 0; i < albums.length; i++) {
|
'title',
|
||||||
if (i !== albums.length - 1)
|
'id',
|
||||||
list += '├── ' + albums[i].title + '\n'
|
'user_id',
|
||||||
+ '│ ├── id: ' + albums[i].id + '\n'
|
'url_code'
|
||||||
+ '│ ├── user id: ' + albums[i].user_id + '\n'
|
]
|
||||||
+ '│ └── url: ' + albums[i].url_code + '\n'
|
return mapRowsToString( albums, 'albums', mapFields )
|
||||||
else
|
|
||||||
list += '└── ' + albums[i].title + '\n'
|
|
||||||
+ ' ├── id: ' + albums[i].id + '\n'
|
|
||||||
+ ' ├── user id: ' + albums[i].user_id + '\n'
|
|
||||||
+ ' └── url: ' + albums[i].url_code + '\n'
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
<ResetComponentWithoutInputs
|
||||||
|
resetState={ resetState }
|
||||||
|
fetchAction={ getAllAlbum }
|
||||||
|
mapObjectToString={ mapAlbumsToString }
|
||||||
|
message={ message }
|
||||||
|
setMessage={ setMessage }
|
||||||
|
componentVisible={ componentVisible }
|
||||||
|
activateConsoleInput={ activateConsoleInput }
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,13 @@ export const store = createStore(rootReducer, persistedState, applyMiddleware(th
|
||||||
|
|
||||||
store.subscribe( () => {
|
store.subscribe( () => {
|
||||||
saveState({
|
saveState({
|
||||||
user: store.getState().user,
|
user: store.getState().user
|
||||||
album: store.getState().album
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
store.subscribe( loadash.throttle( () => {
|
store.subscribe( loadash.throttle( () => {
|
||||||
saveState({
|
saveState({
|
||||||
user: store.getState().user,
|
user: store.getState().user
|
||||||
album: store.getState().album
|
|
||||||
})
|
})
|
||||||
}, 1000))
|
}, 1000))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue