// useEntryIcon.js
const useEntryIcon = (callback) => {
const [entryIcon, setEntryIcon] = useState('floppy')
const { api } = useApiContext()
const renderEntryIconColumn = useCallback(
({
align = 'center',
headerAlign = 'center',
filterable = false,
sortable = false,
resizable = false,
disableColumnMenu = false,
title,
id,
...rest
}) => ({
align,
headerAlign,
filterable,
sortable,
resizable,
disableColumnMenu,
renderCell: ({ id: rowId, row }) => {
const params = { rowId, row }
return (
// EntriesIcon renders an svg based on `entryIcon`
<EntriesIcon
iconType={entryIcon}
title={typeof title === 'string' ? title : title(rowId)}
tabIndex={0}
onClick={(e) => callback(params, e)}
onKeyDown={(e) => {
if (e.key === ' ' || e.key === 'Enter') {
callback(params, e)
}
}}
/>
)
},
...rest,
}),
[callback, entryIcon]
)
useEffect(() => {
api
.get('/api/app-info/entry-icon')
.then(({ data }) => setEntryIcon(data))
.catch(() => setEntryIcon('floppy'))
}, [api])
return renderEntryIconColumn
}
// useEntryIcon.js
const useEntryIcon = (callback) => {
const [entryIcon, setEntryIcon] = useState('floppy')
const { api } = useApiContext()
const renderEntryIconColumn = useCallback(
({
align = 'center',
headerAlign = 'center',
filterable = false,
sortable = false,
resizable = false,
disableColumnMenu = false,
title,
id,
...rest
}) => ({
align,
headerAlign,
filterable,
sortable,
resizable,
disableColumnMenu,
renderCell: ({ id: rowId, row }) => {
const params = { rowId, row }
return (
// EntriesIcon renders an svg based on `entryIcon`
<EntriesIcon
iconType={entryIcon}
title={typeof title === 'string' ? title : title(rowId)}
tabIndex={0}
onClick={(e) => callback(params, e)}
onKeyDown={(e) => {
if (e.key === ' ' || e.key === 'Enter') {
callback(params, e)
}
}}
/>
)
},
...rest,
}),
[callback, entryIcon]
)
useEffect(() => {
api
.get('/api/app-info/entry-icon')
.then(({ data }) => setEntryIcon(data))
.catch(() => setEntryIcon('floppy'))
}, [api])
return renderEntryIconColumn
}