<commit_before><template lang="pug">
  form
    p
      label Name
      input(
        v-model="name"
      )

    p
      label Website
      input(
        v-model="website"
      )

    p
      label Location
      input(
        v-model="location"
      )

    p
      label Add skill
      input(
        v-model="newSkill.name"
        @keyup.enter="addSkill"
      )
      button(@click="addSkill") Add skill

    ul
      li(v-for="skill in selectableSkills")
        label
          input(
            type="checkbox"
            v-model="skill.checked"
          )
          span {{skill.name}}
    p {{selectedSkills | json}}
    p
      button Cancel
      button(@click="save") Save
</template>

<script>
  import firebase from 'config/firebase';
  import Skill from 'models/skill';

  const defaultResource = {
    name: '',
    website: '',
    location: '',
    newSkill: new Skill(),
    chosenSkills: [],
  };

  export default {
    name: 'add-resource',

    data() {
      return Object.assign({}, defaultResource);
    },

    computed: {
      selectableSkills() {
        return this.skills;
      },

      selectedSkills() {
        return this.selectableSkills.filter(skill => skill.checked);
      },
    },

    methods: {
      save() {
        const newResourceRef = firebase
          .database()
          .ref('/resources')
          .push();

        // Merge with key
        const newResource = Object.assign({
          key: newResourceRef.key,
        }, this.$data);

        newResourceRef.set(newResource);

        this.$data = Object.assign({}, defaultResource);
      },

      addSkill() {
        if (!this.newSkill.name) return;
        this.newSkill.push();
        this.newSkill = new Skill();
      },
    },

    vuex: {
      getters: {
        user: state => state.auth.user,
        skills: state => state.pool.skills,
      },
    },
  };
</script><commit_msg>Update namespace and simplify firebase calls<commit_after><template lang="pug">
  form
    p
      label Name
      input(
        v-model="resource.name"
      )

    p
      label Website
      input(
        v-model="resource.website"
      )

    p
      label Location
      input(
        v-model="resource.location"
      )

    p
      label Add skill
      input(
        v-model="resource.newSkill.name"
        @keyup.enter="addSkill"
      )
      button(@click="addSkill") Add skill

    ul
      li(v-for="skill in skills")
        label(@click="toggleSkill")
          input(
            type="checkbox"
          )
          span {{skill.name}}
    p {{resource.selectedSkills | json}}
    p
      button Cancel
      button(@click.prevent="save") Save
</template>

<script>
  import Skill from 'models/skill';
  import Resource from 'models/resource';

  export default {
    name: 'add-resource',

    data() {
      return { resource: new Resource() };
    },

    computed: {
      selectableSkills() {
        return this.skills;
      },

      selectedSkills() {
        return this.selectableSkills.filter(skill => skill.checked);
      },
    },

    methods: {
      save() {
        this.resource.set()
          .catch(err => {
            throw err;
          });
        this.resource = new Resource();
      },

      toggleSkill(e, o) {
        this.blah = o;
        this.bla2 = e;
        debugger;
      },

      addSkill() {
        if (!this.resource.newSkill.name) return;
        this.resource.newSkill.set();
        this.resource.newSkill = new Skill();
      },
    },

    vuex: {
      getters: {
        user: state => state.auth.user,
        skills: state => state.pool.skills,
      },
    },
  };
</script>
{'fraction_non_alphanumeric': 0.1304111080860332, 'fraction_numerical': 0.0002722570106180234, 'mean_word_length': 1.637473079684135, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 18, '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': '2998999', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1115, 'n_words': 228}