|
|
@ -22,15 +22,27 @@ export interface TagChange { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export interface ManageTagsWindowState extends WindowState { |
|
|
|
export interface ManageTagsWindowState extends WindowState { |
|
|
|
fetchedTags: any[], |
|
|
|
fetchedTags: any[] | null, |
|
|
|
pendingChanges: TagChange[], |
|
|
|
pendingChanges: TagChange[], |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export enum ManageTagsWindowActions { |
|
|
|
export enum ManageTagsWindowActions { |
|
|
|
|
|
|
|
SetFetchedTags = "SetFetchedTags", |
|
|
|
|
|
|
|
SetPendingChanges = "SetPendingChanges", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function ManageTagsWindowReducer(state: ManageTagsWindowState, action: any) { |
|
|
|
export function ManageTagsWindowReducer(state: ManageTagsWindowState, action: any) { |
|
|
|
switch (action.type) { |
|
|
|
switch (action.type) { |
|
|
|
|
|
|
|
case ManageTagsWindowActions.SetFetchedTags: |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
...state, |
|
|
|
|
|
|
|
fetchedTags: action.value, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case ManageTagsWindowActions.SetPendingChanges: |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
...state, |
|
|
|
|
|
|
|
pendingChanges: action.value, |
|
|
|
|
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
throw new Error("Unimplemented ManageTagsWindow state update.") |
|
|
|
throw new Error("Unimplemented ManageTagsWindow state update.") |
|
|
|
} |
|
|
|
} |
|
|
@ -126,16 +138,22 @@ export interface IProps { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default function ManageTagsWindow(props: IProps) { |
|
|
|
export default function ManageTagsWindow(props: IProps) { |
|
|
|
const [tags, setTags] = React.useState<any[]>([]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (props.state.fetchedTags !== null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
(async () => { |
|
|
|
(async () => { |
|
|
|
const allTags = await getAllTags(); |
|
|
|
const allTags = await getAllTags(); |
|
|
|
// We have the tags in list form. Now, we want to organize
|
|
|
|
// We have the tags in list form. Now, we want to organize
|
|
|
|
// them hierarchically by giving each tag a "children" prop.
|
|
|
|
// them hierarchically by giving each tag a "children" prop.
|
|
|
|
setTags(organiseTags(allTags, null)); |
|
|
|
props.dispatch({ |
|
|
|
|
|
|
|
type: ManageTagsWindowActions.SetFetchedTags, |
|
|
|
|
|
|
|
value: organiseTags(allTags, null), |
|
|
|
|
|
|
|
}); |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
}, []); |
|
|
|
}, [props.state.fetchedTags]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tags = props.state.fetchedTags || []; |
|
|
|
|
|
|
|
|
|
|
|
return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> |
|
|
|
return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> |
|
|
|
<Box |
|
|
|
<Box |
|
|
@ -158,7 +176,6 @@ export default function ManageTagsWindow(props: IProps) { |
|
|
|
width="80%" |
|
|
|
width="80%" |
|
|
|
> |
|
|
|
> |
|
|
|
{tags && tags.length && tags.map((tag: any) => { |
|
|
|
{tags && tags.length && tags.map((tag: any) => { |
|
|
|
console.log("Tags:", tags); |
|
|
|
|
|
|
|
return <Box mt={1}><SingleTag tag={tag} prependElems={[]} /></Box>; |
|
|
|
return <Box mt={1}><SingleTag tag={tag} prependElems={[]} /></Box>; |
|
|
|
})} |
|
|
|
})} |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|