feat: auto sync after created

This commit is contained in:
shiweisong.ssw 2023-06-30 15:19:36 +08:00
parent 07df9369c9
commit df9d4d2f38
2 changed files with 115 additions and 2 deletions

View File

@ -13,6 +13,8 @@ import {
Input,
Textarea,
Chip,
Switch,
Typography,
styled
} from '@/lib/mui'
import moment from 'moment'
@ -72,6 +74,7 @@ const Documents = () => {
const [originFileObj, setOriginFileObj] = useState<any>(null)
const [total, setTotal] = useState<number>(0)
const [current, setCurrent] = useState<number>(0)
const [synchChecked, setSynchChecked] = useState<boolean>(true)
const props: UploadProps = {
name: 'file',
multiple: false,
@ -422,6 +425,22 @@ const Documents = () => {
/>
</>
)}
<Typography
component="label"
sx={{
marginTop: '20px'
}}
endDecorator={
<Switch
checked={synchChecked}
onChange={(event: any) =>
setSynchChecked(event.target.checked)
}
/>
}
>
Synch:
</Typography>
</Box>
<Button
variant="outlined"
@ -450,6 +469,18 @@ const Documents = () => {
}
)
const data = await res.json()
data.success && fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
if (data.success) {
message.success('success')
setIsAddDocumentModalShow(false)
@ -492,6 +523,18 @@ const Documents = () => {
}
)
const data = await res.json()
data.success && fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
if (data.success) {
message.success('success')
setIsAddDocumentModalShow(false)
@ -538,6 +581,18 @@ const Documents = () => {
}
)
const data = await res.json()
data.success && fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
if (data.success) {
message.success('success')
setIsAddDocumentModalShow(false)

View File

@ -16,6 +16,8 @@ import {
Input,
Textarea,
Chip,
Switch,
Typography,
styled
} from '@/lib/mui'
import { fetchBaseURL } from '@/app/datastores/constants'
@ -71,6 +73,7 @@ const Index = () => {
const [textSource, setTextSource] = useState<string>('')
const [text, setText] = useState<string>('')
const [originFileObj, setOriginFileObj] = useState<any>(null)
const [synchChecked, setSynchChecked] = useState<boolean>(true)
const props: UploadProps = {
name: 'file',
multiple: false,
@ -214,7 +217,10 @@ const Index = () => {
{stepsOfAddingSpace.map((item: any, index: number) => (
<Item
key={item}
sx={{ fontWeight: activeStep === index ? 'bold' : '', color: activeStep === index ? '#814DDE' : '' }}
sx={{
fontWeight: activeStep === index ? 'bold' : '',
color: activeStep === index ? '#814DDE' : ''
}}
>
{item}
</Item>
@ -361,9 +367,25 @@ const Index = () => {
/>
</>
)}
<Typography
component="label"
sx={{
marginTop: '20px'
}}
endDecorator={
<Switch
checked={synchChecked}
onChange={(event: any) =>
setSynchChecked(event.target.checked)
}
/>
}
>
Synch:
</Typography>
</Box>
<Button
variant='outlined'
variant="outlined"
onClick={async () => {
if (documentName === '') {
message.error('Please input the name')
@ -392,6 +414,18 @@ const Index = () => {
if (data.success) {
message.success('success')
setIsAddKnowledgeSpaceModalShow(false)
fetch(
`${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
} else {
message.error(data.err_msg || 'failed')
}
@ -415,6 +449,18 @@ const Index = () => {
if (data.success) {
message.success('success')
setIsAddKnowledgeSpaceModalShow(false)
fetch(
`${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
} else {
message.error(data.err_msg || 'failed')
}
@ -442,6 +488,18 @@ const Index = () => {
if (data.success) {
message.success('success')
setIsAddKnowledgeSpaceModalShow(false)
fetch(
`${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
} else {
message.error(data.err_msg || 'failed')
}