Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2490 - added v-skills and v-skills-onMount directives
- Loading branch information
Showing
5 changed files
with
70 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
dashboard-prime/src/components/utils/SkillsReporterDirective.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useDebounceFn } from '@vueuse/core' | ||
import { SkillsReporter, SUCCESS_EVENT, FAILURE_EVENT } from '@skilltree/skills-client-js'; | ||
import { useAppConfig } from '@/common-components/stores/UseAppConfig.js' | ||
|
||
export const useSkillsReporterDirective = () => { | ||
const eventCache = new WeakMap(); | ||
const appConfig = useAppConfig() | ||
const eventListener = (el, skillId) => useDebounceFn(() => { | ||
SkillsReporter.reportSkill(skillId) | ||
.then((result) => { | ||
const event = new CustomEvent(SUCCESS_EVENT, { detail: result }); | ||
el.dispatchEvent(event); | ||
}) | ||
.catch((error) => { | ||
const event = new CustomEvent(FAILURE_EVENT, { detail: error }); | ||
el.dispatchEvent(event); | ||
}); | ||
}, appConfig.formFieldDebounceInMs); | ||
|
||
const vSkills = { | ||
mounted: (el, binding) => { | ||
const eventContext = { | ||
name: binding.arg ? binding.arg : 'click', | ||
handler: eventListener(el, binding.value), | ||
}; | ||
el.addEventListener(eventContext.name, eventContext.handler); | ||
eventCache.set(el, eventContext); | ||
}, | ||
unmounted: (el) => { | ||
const eventContext = eventCache.get(el); | ||
setTimeout(() => { | ||
el.removeEventListener(eventContext.name, eventContext.handler); | ||
eventCache.delete(el); | ||
}); | ||
} | ||
} | ||
|
||
const vSkillsOnMounted = { | ||
mounted: (el, binding) => { | ||
const {projectId, subjectId, skillId} = binding.value; | ||
const skillsReporter = new SkillsReporter(projectId, subjectId, skillId); | ||
skillsReporter.render(el); | ||
}, | ||
} | ||
|
||
return { | ||
vSkills, | ||
vSkillsOnMounted, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters