<commit_before>import React from 'react'
import { Service, SyncConfig } from '@/background/sync-manager/services/shanbay'
import { formItemModalLayout } from '../helpers'
import { MsgSyncServiceInit, MsgType, MsgSyncServiceUpload, SyncServiceUploadOp } from '@/typings/message'
import { message } from '@/_helpers/browser-api'
import { TranslationFunction } from 'i18next'
import { getWords } from '@/_helpers/record-manager'

import { Form, Modal, Button, Switch, message as AntdMessage } from 'antd'

export interface WebdavModalProps {
  syncConfig?: SyncConfig
  t: TranslationFunction
  show: boolean
  onClose: () => void
}

export interface ShanbayModalState {
  syncConfig: SyncConfig
}

export default class ShanbayModal extends React.Component<WebdavModalProps, ShanbayModalState> {
  state: ShanbayModalState = {
    syncConfig: this.props.syncConfig || Service.getDefaultConfig(),
  }

  closeSyncService = () => {
    this.props.onClose()
  }

  handleEnableChanged = async (checked: boolean) => {
    if (checked) {
      const response = await message.send<MsgSyncServiceInit<SyncConfig>>({
        type: MsgType.SyncServiceInit,
        serviceID: Service.id,
        config: this.state.syncConfig,
      }).catch((e) => ({ error: e }))

      if (response && response.error) {
        alert(this.props.t('sync_shanbay_login'))
        Service.openLogin()
        return
      }
    }

    this.setState(prevState => ({
      syncConfig: {
        ...prevState.syncConfig,
        enable: checked,
      }
    }))
  }

  handleSyncAll = async () => {
    const { t } = this.props
    const { total } = await getWords('notebook', {
      itemsPerPage: 1,
      filters: {},
    })
    if (total > 50 && !confirm(t('sync_shanbay_sync_all_confirm'))) {
      return
    }

    AntdMessage.success(t('sync_start'))

    await message.send<MsgSyncServiceUpload>({
      type: MsgType.SyncServiceUpload,
      op: SyncServiceUploadOp.Add,
      serviceID: Service.id,
      force: true,
    })
    .catch(() => ({ error: 'unknown' }))
    .then(e => {<commit_msg>fix(sync): proper trun off shanbay<commit_after>import React from 'react'
import { Service, SyncConfig } from '@/background/sync-manager/services/shanbay'
import { setSyncConfig } from '@/background/sync-manager/helpers'
import { formItemModalLayout } from '../helpers'
import { MsgSyncServiceInit, MsgType, MsgSyncServiceUpload, SyncServiceUploadOp } from '@/typings/message'
import { message } from '@/_helpers/browser-api'
import { TranslationFunction } from 'i18next'
import { getWords } from '@/_helpers/record-manager'

import { Form, Modal, Button, Switch, message as AntdMessage } from 'antd'

export interface WebdavModalProps {
  syncConfig?: SyncConfig
  t: TranslationFunction
  show: boolean
  onClose: () => void
}

export interface ShanbayModalState {
  syncConfig: SyncConfig
}

export default class ShanbayModal extends React.Component<WebdavModalProps, ShanbayModalState> {
  state: ShanbayModalState = {
    syncConfig: this.props.syncConfig || Service.getDefaultConfig(),
  }

  closeSyncService = () => {
    this.props.onClose()
  }

  handleEnableChanged = async (checked: boolean) => {
    if (checked) {
      const response = await message.send<MsgSyncServiceInit<SyncConfig>>({
        type: MsgType.SyncServiceInit,
        serviceID: Service.id,
        config: this.state.syncConfig,
      }).catch((e) => ({ error: e }))

      if (response && response.error) {
        alert(this.props.t('sync_shanbay_login'))
        Service.openLogin()
        return
      }
    } else {
      setSyncConfig('shanbay', {
        ...this.state.syncConfig,
        enable: false,
      })
    }

    this.setState(prevState => ({
      syncConfig: {
        ...prevState.syncConfig,
        enable: checked,
      }
    }))
  }

  handleSyncAll = async () => {
    const { t } = this.props
    const { total } = await getWords('notebook', {
      itemsPerPage: 1,
      filters: {},
    })
    if (total > 50 && !confirm(t('sync_shanbay_sync_all_confirm'))) {
      return
    }

    AntdMessage.success(t('sync_start'))

    await message.send<MsgSyncServiceUpload>({
      type: MsgType.SyncServiceUpload,
      op: SyncServiceUploadOp.Add,
      serviceID: Service.id,
      force: true,
    })
    .catch(() => ({ error: 'unknown' }))
    .then(e => {
{'fraction_non_alphanumeric': 0.13049482163406215, 'fraction_numerical': 0.0023014959723820483, 'mean_word_length': 3.174831892411143, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '824543', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1328, 'n_words': 281}