<commit_before>import "./Hint.scss";

import React from "react";
import { FaTimes } from "react-icons/fa";

import { cache } from "@fider/services";

interface HintProps {
  permanentCloseKey?: string;
  condition?: boolean;
}

interface HintState {
  isClosed: boolean;
}

export class Hint extends React.Component<HintProps, HintState> {
  private cacheKey: string | undefined;

  constructor(props: HintProps) {
    super(props);
    this.cacheKey = this.props.permanentCloseKey ? `Hint-Closed-${this.props.permanentCloseKey}` : undefined;
    this.state = {
      isClosed: this.cacheKey ? cache.local.has(this.cacheKey) : false
    };
  }

  private close = () => {
    if (this.cacheKey) {
      cache.local.set(this.cacheKey, "true");
    }

    this.setState({
      isClosed: true
    });
  };

  public render() {
    if (this.props.condition === false || this.state.isClosed) {
      return null;
    }

    return (
      <p className="c-hint">
        <strong>HINT:</strong> {this.props.children}
        {this.cacheKey && <FaTimes onClick={this.close} className="close" />}
      </p>
    );
  }
}<commit_msg>refactor: migrate Hint to React Hooks (#788)<commit_after>import "./Hint.scss";

import React, { useState } from "react";
import { FaTimes } from "react-icons/fa";

import { cache } from "@fider/services";

interface HintProps {
  permanentCloseKey?: string;
  condition?: boolean;
}

export const Hint: React.FC<HintProps> = props => {
  const cacheKey: string | undefined = props.permanentCloseKey ? `Hint-Closed-${props.permanentCloseKey}` : undefined;
  const [isClosed, setIsClosed] = useState<boolean>(cacheKey ? cache.local.has(cacheKey) : false);

  const close = () => {
    if (cacheKey) {
      cache.local.set(cacheKey, "true");
    }
    setIsClosed(true);
  };

  if (props.condition === false || isClosed) {
    return null;
  }
  return (
    <p className="c-hint">
      <strong>HINT:</strong> {props.children}
      {cacheKey && <FaTimes onClick={close} className="close" />}
    </p>
  );
};
{'fraction_non_alphanumeric': 0.15641908509591737, 'fraction_numerical': 0.0014756517461878996, 'mean_word_length': 3.3461538461538463, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 19, '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': '7228299', 'n_tokens_mistral': 684, 'n_tokens_neox': 668, 'n_words': 141}