<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import ScoreJson from 'interfaces/score-json';
import { route } from 'laroute';
import { action, makeObservable, observable, runInAction } from 'mobx';
import OsuCore from 'osu-core';

export default class ScorePins {
  @observable pins = new Map<string, boolean>();

  constructor(private core: OsuCore) {
    makeObservable(this);
  }

  apiPin(score: ScoreJson, toPin: boolean): JQuery.jqXHR<void> {
    const pin = score.current_user_attributes.pin;
    if (pin == null) {
      throw new Error("can't pin score without current user attributes");
    }

    return $.ajax(route('score-pins.store'), {
      data: pin,
      dataType: 'json',
      method: toPin ? 'POST' : 'DELETE',
    // Use setTimeout to allow cleanup process to do their thing in `.done` callback
    // before announcing the score pin state has changed. Mainly relevant for
    // components which is gone after score is unpinned.
    }).done(() => window.setTimeout(action(() => {
      this.markPinned(score, toPin);
      $.publish('score:pin', [toPin, score]);
    })));<commit_msg>How to grammar<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import ScoreJson from 'interfaces/score-json';
import { route } from 'laroute';
import { action, makeObservable, observable, runInAction } from 'mobx';
import OsuCore from 'osu-core';

export default class ScorePins {
  @observable pins = new Map<string, boolean>();

  constructor(private core: OsuCore) {
    makeObservable(this);
  }

  apiPin(score: ScoreJson, toPin: boolean): JQuery.jqXHR<void> {
    const pin = score.current_user_attributes.pin;
    if (pin == null) {
      throw new Error("can't pin score without current user attributes");
    }

    return $.ajax(route('score-pins.store'), {
      data: pin,
      dataType: 'json',
      method: toPin ? 'POST' : 'DELETE',
    // Use setTimeout to allow cleanup process to do their thing in `.done` callback
    // before announcing the score pin state has changed. Mainly relevant for
    // component which is gone after score is unpinned.
    }).done(() => window.setTimeout(action(() => {
      this.markPinned(score, toPin);
      $.publish('score:pin', [toPin, score]);
    })));
{'fraction_non_alphanumeric': 0.12510024057738572, 'fraction_numerical': 0.0016038492381716118, 'mean_word_length': 3.5779816513761467, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '7310845', 'n_tokens_mistral': 748, 'n_tokens_neox': 728, 'n_words': 260}