2023-03-23 17:15:50 +00:00
|
|
|
import type { Topic } from '../../../graphql/types.gen'
|
|
|
|
import { createOptions, Select } from '@thisbeyond/solid-select'
|
|
|
|
import { useLocalize } from '../../../context/localize'
|
|
|
|
import '@thisbeyond/solid-select/style.css'
|
2023-03-23 17:47:36 +00:00
|
|
|
import './TopicSelect.scss'
|
2023-03-23 17:54:33 +00:00
|
|
|
import { clone } from '../../../utils/clone'
|
2023-03-23 17:15:50 +00:00
|
|
|
|
|
|
|
type TopicSelectProps = {
|
|
|
|
topics: Topic[]
|
2023-03-23 17:47:36 +00:00
|
|
|
selectedTopics: Topic[]
|
2023-03-23 17:15:50 +00:00
|
|
|
onChange: (selectedTopics: Topic[]) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const TopicSelect = (props: TopicSelectProps) => {
|
|
|
|
const { t } = useLocalize()
|
|
|
|
|
2023-03-23 17:47:36 +00:00
|
|
|
const selectProps = createOptions(props.topics, {
|
|
|
|
key: 'title',
|
|
|
|
disable: (topic) => {
|
|
|
|
console.log({ selectedTopics: clone(props.selectedTopics) })
|
|
|
|
return props.selectedTopics.includes(topic)
|
|
|
|
}
|
|
|
|
})
|
2023-03-23 17:15:50 +00:00
|
|
|
|
|
|
|
const handleChange = (selectedTopics: Topic[]) => {
|
|
|
|
props.onChange(selectedTopics)
|
|
|
|
}
|
|
|
|
|
2023-03-23 17:47:36 +00:00
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
multiple={true}
|
|
|
|
{...selectProps}
|
|
|
|
placeholder={t('Topics')}
|
|
|
|
class="TopicSelect"
|
|
|
|
onChange={handleChange}
|
|
|
|
/>
|
|
|
|
)
|
2023-03-23 17:15:50 +00:00
|
|
|
}
|