<commit_before><template>
    <header class="mdc-toolbar">
      <div class="mdc-toolbar__row">
        <section class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <span class="mdc-toolbar__title">Github for Fashion</span>
        </section>
        <section class="mdc-toolbar__section mdc-toolbar__section--align-end" role="toolbar">
          <router-link :to="{name: 'Home'}" class="material-icons">home</router-link>
        </section>
        <section class="mdc-toolbar__section mdc-toolbar__section--align-end" role="toolbar">
          <router-link :to="{name: 'create'}" class="material-icons">add</router-link>
        </section>
        <section v-if="state.name != null" class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <span>{{ state.name }}</span>
        </section>
        <section v-if="state.name == null" class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <span>{{ state.login }}</span>
        </section>
        <section v-if="state.name || state.login" class="mdc-toolbar__section mdc-toolbar__section--align-start">
           <a @click.prevent="disconnect" href="#">Logout</a>
        </section>
        <section v-else class="mdc-toolbar__section mdc-toolbar__section--align-start" id="login">
          <a @click.prevent="showLogin = true" href="#">Login</a>
          <div v-if="showLogin">
            <label>Paste your Token</label>
            <input type="text" v-model="logininput">
          <div v-if="loader" class="loader_login"></div>
          <a class="link_login" href="https://github.com/settings/tokens">Where find it ?</a>
          <p>Info: When creating it, please enable the right to access public directories.</p>
        </div>
        </section>
      </div>
    </header>
</template>

<script>
import GitHub from 'github-api';

import sessionStore from '../loginStore';


export default {
  name: 'g-header',
  data() {
    return {
      token: '',
      state: sessionStore.state,
      showLogin: false,
      loader: false,
      logininput: '',
    };
  },
  computed: {
    name() {
      return this.state.name;
    },
  },
  methods: {
    disconnect() {
      sessionStore.clearLogin();
      this.state.name = '';
      this.state.login = '';
    },
  },
  watch: {
    /* eslint-disable object-shorthand */
    /* eslint-disable func-names */
    logininput: function (val) {
      if (val.length >= 40) {
        this.loader = true;
        this.token = val.trim();

        const gh = new GitHub({
          token: val.trim(),
        });

        gh.getUser().getProfile().then((user) => {
          sessionStore.setLogin(val.trim(), user.data.login, user.data.name);
          this.state.name = user.data.name;
          this.state.login = user.data.login;
          this.showLogin = false;
          this.loader = false;<commit_msg>If empty name => displaying login<commit_after><template>
    <header class="mdc-toolbar">
      <div class="mdc-toolbar__row">
        <section class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <span class="mdc-toolbar__title">Github for Fashion</span>
        </section>
        <section class="mdc-toolbar__section mdc-toolbar__section--align-end" role="toolbar">
          <router-link :to="{name: 'Home'}" class="material-icons">home</router-link>
        </section>
        <section class="mdc-toolbar__section mdc-toolbar__section--align-end" role="toolbar">
          <router-link :to="{name: 'create'}" class="material-icons">add</router-link>
        </section>
        <section v-if="state.name !== null" class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <span>{{ state.name }}</span>
        </section>
        <section v-if="state.name === null" class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <span>{{ state.login }}</span>
        </section>
        <section v-if="state.name || state.login" class="mdc-toolbar__section mdc-toolbar__section--align-start">
           <a @click.prevent="disconnect" href="#">Logout</a>
        </section>
        <section v-else class="mdc-toolbar__section mdc-toolbar__section--align-start" id="login">
          <a @click.prevent="showLogin = true" href="#">Login</a>
          <div v-if="showLogin">
            <label>Paste your Token</label>
            <input type="text" v-model="logininput">
          <div v-if="loader" class="loader_login"></div>
          <a class="link_login" href="https://github.com/settings/tokens">Where find it ?</a>
          <p>Info: When creating it, please enable the right to access public directories.</p>
        </div>
        </section>
      </div>
    </header>
</template>

<script>
import GitHub from 'github-api';

import sessionStore from '../loginStore';


export default {
  name: 'g-header',
  data() {
    return {
      token: '',
      state: sessionStore.state,
      showLogin: false,
      loader: false,
      logininput: '',
    };
  },
  computed: {
    name() {
      return this.state.name;
    },
  },
  methods: {
    disconnect() {
      sessionStore.clearLogin();
      this.state.name = '';
      this.state.login = '';
    },
  },
  watch: {
    /* eslint-disable object-shorthand */
    /* eslint-disable func-names */
    logininput: function (val) {
      var val = val.trim();
      if (val.length >= 2) {
        this.loader = true;
        this.token = val;

        const gh = new GitHub({
          token: val.trim(),
        });

        gh.getUser().getProfile().then((user) => {
          sessionStore.setLogin(val.trim(), user.data.login, user.data.name);
          this.state.name = user.data.name;
          this.state.login = user.data.login;
          this.showLogin = false;
          this.loader = false;
{'fraction_non_alphanumeric': 0.1649948114839156, 'fraction_numerical': 0.0005188516084399862, 'mean_word_length': 2.4463647199046483, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 100, 'https://': 2, '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': '2614471', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1745, 'n_words': 338}