File size: 3,286 Bytes
537a6f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import "../chunks/DKem_M_z.js";
import "../chunks/DwLkIEu4.js";
import { p as push, i as getContext, o as onMount, k as get, w as set, l as legacy_pre_effect, n as legacy_pre_effect_reset, g as comment, h as first_child, a as append, b as pop, s as setup_stores, q as mutable_source, e as store_get } from "../chunks/B-Kw_l3V.js";
import { i as if_block } from "../chunks/DWHK2A9K.js";
import { i as init } from "../chunks/CUpGYt-B.js";
import { t as toast } from "../chunks/B4Bn1xMI.js";
import { g as goto } from "../chunks/BLfIdBii.js";
import { e as skills } from "../chunks/BJ3rUC-5.js";
import { a as getSkillById, b as updateSkillById, g as getSkills } from "../chunks/DRvubTJA.js";
import { p as page } from "../chunks/4ha_GQi5.js";
import { S as SkillEditor } from "../chunks/fQ6E729m.js";
function _page($$anchor, $$props) {
  push($$props, false);
  const $page = () => store_get(page, "$page", $$stores);
  const $i18n = () => store_get(i18n, "$i18n", $$stores);
  const [$$stores, $$cleanup] = setup_stores();
  const skillId = mutable_source();
  const i18n = getContext("i18n");
  let skill = mutable_source(null);
  let disabled = mutable_source(false);
  const onSubmit = async (_skill) => {
    const updatedSkill = await updateSkillById(localStorage.token, get(skillId), _skill).catch((error) => {
      toast.error(`${error}`);
      return null;
    });
    if (updatedSkill) {
      toast.success($i18n().t("Skill updated successfully"));
      await skills.set(await getSkills(localStorage.token));
      set(skill, {
        id: updatedSkill.id,
        name: updatedSkill.name,
        description: updatedSkill.description,
        content: updatedSkill.content,
        is_active: updatedSkill.is_active,
        access_grants: (updatedSkill == null ? void 0 : updatedSkill.access_grants) === void 0 ? [] : updatedSkill == null ? void 0 : updatedSkill.access_grants
      });
    }
  };
  onMount(async () => {
    if (get(skillId)) {
      const _skill = await getSkillById(localStorage.token, get(skillId)).catch((error) => {
        toast.error(`${error}`);
        return null;
      });
      if (_skill) {
        set(disabled, !_skill.write_access);
        set(skill, {
          id: _skill.id,
          name: _skill.name,
          description: _skill.description,
          content: _skill.content,
          is_active: _skill.is_active,
          access_grants: (_skill == null ? void 0 : _skill.access_grants) === void 0 ? [] : _skill == null ? void 0 : _skill.access_grants
        });
      } else {
        goto("/workspace/skills");
      }
    } else {
      goto("/workspace/skills");
    }
  });
  legacy_pre_effect(() => $page(), () => {
    set(skillId, $page().url.searchParams.get("id"));
  });
  legacy_pre_effect_reset();
  init();
  var fragment = comment();
  var node = first_child(fragment);
  {
    var consequent = ($$anchor2) => {
      SkillEditor($$anchor2, {
        get skill() {
          return get(skill);
        },
        onSubmit,
        get disabled() {
          return get(disabled);
        },
        edit: true
      });
    };
    if_block(node, ($$render) => {
      if (get(skill)) $$render(consequent);
    });
  }
  append($$anchor, fragment);
  pop();
  $$cleanup();
}
export {
  _page as component
};