<commit_before>import Cookies, { CookieAttributes } from 'js-cookie'
import { action, observable } from 'mobx'
import { Config } from '../model/config/Config'

export class DefaultConfig implements Config {
  @observable paintTargets: boolean
  @observable serverURL: string
  @observable saveToCookie: boolean

  private readonly keys = {
    paintTargets: 'paintTargets',
    serverURL: 'serverURL',
    saveToCookie: 'saveToCookie',
  }

  // 1年
  private readonly expire: CookieAttributes = { expires: 86400 * 365 }

  constructor() {
    this.paintTargets = !(Cookies.get(this.keys.paintTargets) === 'false')
    this.serverURL = Cookies.get(this.keys.serverURL) || ''
    this.saveToCookie = Cookies.get(this.keys.saveToCookie) === 'true'
  }

  @action
  async setPaintTargets(b: boolean): Promise<void> {
    this.paintTargets = b
    if (this.saveToCookie)
      Cookies.set(this.keys.paintTargets, String(b), this.expire)
  }

  @action
  async setServerURL(s: string): Promise<void> {
    this.serverURL = s
    if (this.saveToCookie) Cookies.set(this.keys.serverURL, s, this.expire)
  }

  @action
  async setSaveToCookie(b: boolean): Promise<void> {
    this.saveToCookie = b
    if (this.saveToCookie)
      return Cookies.set(this.keys.saveToCookie, String(b), this.expire)<commit_msg>:bug: Cookie に保存を on にしたとき、入力済みの値を保存してなかった<commit_after>import Cookies, { CookieAttributes } from 'js-cookie'
import { action, observable } from 'mobx'
import { Config } from '../model/config/Config'

export class DefaultConfig implements Config {
  @observable paintTargets: boolean
  @observable serverURL: string
  @observable saveToCookie: boolean

  private readonly keys = {
    paintTargets: 'paintTargets',
    serverURL: 'serverURL',
    saveToCookie: 'saveToCookie',
  }

  // 1年
  private readonly expire: CookieAttributes = { expires: 86400 * 365 }

  constructor() {
    this.paintTargets = !(Cookies.get(this.keys.paintTargets) === 'false')
    this.serverURL = Cookies.get(this.keys.serverURL) || ''
    this.saveToCookie = Cookies.get(this.keys.saveToCookie) === 'true'
  }

  @action
  async setPaintTargets(b: boolean): Promise<void> {
    this.paintTargets = b
    if (this.saveToCookie)
      Cookies.set(this.keys.paintTargets, String(b), this.expire)
  }

  @action
  async setServerURL(s: string): Promise<void> {
    this.serverURL = s
    if (this.saveToCookie) Cookies.set(this.keys.serverURL, s, this.expire)
  }

  @action
  async setSaveToCookie(b: boolean): Promise<void> {
    this.saveToCookie = b

    if (this.saveToCookie) {
      const { saveToCookie, serverURL, paintTargets } = this.keys
      const expire = this.expire
      Cookies.set(saveToCookie, String(b), expire)
      Cookies.set(serverURL, this.serverURL, expire)
      Cookies.set(paintTargets, String(this.paintTargets), expire)
      return
    }
{'fraction_non_alphanumeric': 0.12359550561797752, 'fraction_numerical': 0.006320224719101123, 'mean_word_length': 3.87008547008547, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '618504', 'n_tokens_mistral': 996, 'n_tokens_neox': 942, 'n_words': 199}