parent
a863e37dd6
commit
1303bac2e0
@ -0,0 +1,3 @@ |
||||
export { fileDecoration, fileDecorationType, FileType } from './lib/types/index' |
||||
export { FileDecorationIcons } from './lib/components/file-decoration-icon' |
||||
|
@ -0,0 +1,48 @@ |
||||
// eslint-disable-next-line no-use-before-define
|
||||
import React, { useEffect, useState } from 'react' |
||||
|
||||
import { fileDecoration, fileDecorationType, FileType } from '../types' |
||||
import FileDecorationCustomIcon from './filedecorationicons/file-decoration-custom-icon' |
||||
import FileDecorationErrorIcon from './filedecorationicons/file-decoration-error-icon' |
||||
import FileDecorationWarningIcon from './filedecorationicons/file-decoration-warning-icon' |
||||
|
||||
export type fileDecorationProps = { |
||||
file: FileType, |
||||
fileDecorations: fileDecoration[] |
||||
} |
||||
|
||||
export const FileDecorationIcons = (props: fileDecorationProps) => { |
||||
const [states, setStates] = useState<fileDecoration[]>([]) |
||||
useEffect(() => { |
||||
//console.log(props.file)
|
||||
//console.log(props.fileState)
|
||||
setStates(props.fileDecorations.filter((fileDecoration) => fileDecoration.path === props.file.path || `${fileDecoration.workspace.name}/${fileDecoration.path}` === props.file.path)) |
||||
}, [props.fileDecorations]) |
||||
|
||||
const getTags = function () { |
||||
if (states && states.length) { |
||||
const elements: JSX.Element[] = [] |
||||
|
||||
for (const [index, state] of states.entries()) { |
||||
switch (state.fileStateType) { |
||||
case fileDecorationType.Error: |
||||
elements.push(<FileDecorationErrorIcon fileState={state} key={index} />) |
||||
break |
||||
case fileDecorationType.Warning: |
||||
elements.push(<FileDecorationWarningIcon fileState={state} key={index}/>) |
||||
break |
||||
case fileDecorationType.Custom: |
||||
elements.push(<FileDecorationCustomIcon fileState={state} key={index} />) |
||||
break |
||||
} |
||||
} |
||||
return elements |
||||
} |
||||
} |
||||
|
||||
return <> |
||||
{getTags()} |
||||
</> |
||||
} |
||||
|
||||
export default FileDecorationIcons |
@ -1,13 +1,13 @@ |
||||
// eslint-disable-next-line no-use-before-define
|
||||
import React from 'react' |
||||
import { fileState } from '../../types' |
||||
import { fileDecoration } from '../../types' |
||||
|
||||
const FileStateCustomIcon = (props: { |
||||
fileState: fileState |
||||
const FileDecorationCustomIcon = (props: { |
||||
fileState: fileDecoration |
||||
}) => { |
||||
return <><span className={`${props.fileState.fileStateIconClass}pr-2`}> |
||||
{props.fileState.fileStateIcon} |
||||
</span></> |
||||
} |
||||
|
||||
export default FileStateCustomIcon |
||||
export default FileDecorationCustomIcon |
@ -0,0 +1,11 @@ |
||||
// eslint-disable-next-line no-use-before-define
|
||||
import React from 'react' |
||||
import { fileDecoration } from '../../types' |
||||
|
||||
const FileDecorationErrorIcon = (props: { |
||||
fileState: fileDecoration |
||||
}) => { |
||||
return <><span className={`${props.fileState.fileStateIconClass} text-danger pr-2`}>{props.fileState.text}</span></> |
||||
} |
||||
|
||||
export default FileDecorationErrorIcon |
@ -0,0 +1,11 @@ |
||||
// eslint-disable-next-line no-use-before-define
|
||||
import React from 'react' |
||||
import { fileDecoration } from '../../types' |
||||
|
||||
const FileDecorationWarningIcon = (props: { |
||||
fileState: fileDecoration |
||||
}) => { |
||||
return <><span className={`${props.fileState.fileStateIconClass} text-warning pr-2`}>{props.fileState.text}</span></> |
||||
} |
||||
|
||||
export default FileDecorationWarningIcon |
@ -1,3 +0,0 @@ |
||||
export { fileState, fileStateType } from './lib/types/index' |
||||
export { FileStateIcons } from './lib/components/file-state-icon' |
||||
|
@ -1,48 +0,0 @@ |
||||
// eslint-disable-next-line no-use-before-define
|
||||
import React, { useEffect, useState } from 'react' |
||||
|
||||
import { fileState, fileStateType, FileType } from '../types' |
||||
import FileStateCustomIcon from './filestates/file-state-custom-icon' |
||||
import FileStateErrorIcon from './filestates/file-state-error-icon' |
||||
import FileStateWarningIcon from './filestates/file-state-warning-icon' |
||||
|
||||
export type fileStateProps = { |
||||
file: FileType, |
||||
fileState: fileState[] |
||||
} |
||||
|
||||
export const FileStateIcons = (props: fileStateProps) => { |
||||
const [states, setStates] = useState<fileState[]>([]) |
||||
useEffect(() => { |
||||
//console.log(props.file)
|
||||
//console.log(props.fileState)
|
||||
setStates(props.fileState.filter((st) => st.path === props.file.path)) |
||||
}, [props.fileState]) |
||||
|
||||
const getTags = function () { |
||||
if (states && states.length) { |
||||
const elements: JSX.Element[] = [] |
||||
|
||||
for (const [index, state] of states.entries()) { |
||||
switch (state.fileStateType) { |
||||
case fileStateType.Error: |
||||
elements.push(<FileStateErrorIcon fileState={state} key={index} />) |
||||
break |
||||
case fileStateType.Warning: |
||||
elements.push(<FileStateWarningIcon fileState={state} key={index}/>) |
||||
break |
||||
case fileStateType.Custom: |
||||
elements.push(<FileStateCustomIcon fileState={state} key={index} />) |
||||
break |
||||
} |
||||
} |
||||
return elements |
||||
} |
||||
} |
||||
|
||||
return <> |
||||
{getTags()} |
||||
</> |
||||
} |
||||
|
||||
export default FileStateIcons |
@ -1,11 +0,0 @@ |
||||
// eslint-disable-next-line no-use-before-define
|
||||
import React from 'react' |
||||
import { fileState } from '../../types' |
||||
|
||||
const FileStateErrorIcon = (props: { |
||||
fileState: fileState |
||||
}) => { |
||||
return <><span className={`${props.fileState.fileStateIconClass} text-danger pr-2`}>{props.fileState.comment}</span></> |
||||
} |
||||
|
||||
export default FileStateErrorIcon |
@ -1,11 +0,0 @@ |
||||
// eslint-disable-next-line no-use-before-define
|
||||
import React from 'react' |
||||
import { fileState } from '../../types' |
||||
|
||||
const FileStateWarningIcon = (props: { |
||||
fileState: fileState |
||||
}) => { |
||||
return <><span className={`${props.fileState.fileStateIconClass} text-warning pr-2`}>{props.fileState.comment}</span></> |
||||
} |
||||
|
||||
export default FileStateWarningIcon |
Loading…
Reference in new issue