{"version":3,"file":"selectionCommittee.67b8ac54.js","sources":["../../../../stores/selectionCommittee.ts"],"sourcesContent":["import _ from 'lodash'\nimport { gql } from '~/apollo/gql'\nimport { defineStore } from 'pinia'\nimport { useDebounceFn } from '@vueuse/core'\n\nexport const useSelectionCommittee = defineStore('selectionCommittee', () => {\n const openFeature = useOpenFeature()\n\n // Film Groups\n const { result, refetch } = useQuery(SelectionFilmGroups, () => ({\n ffid: openFeature.getNumber('current_film_festival'),\n poster: openFeature.getObject('asset_type_ids').poster,\n }), { clientId: 'selection' })\n const filmGroups = computed(() => result.value?.filmGroups || [])\n const awards = computed(() => result.value?.awards || [])\n const filmGroup = computed(() => {\n const route = useRoute()\n if (!route.params.filmGroupId) return null\n\n return filmGroups.value.find(\n (fg) => fg.id.toString() == route.params.filmGroupId\n )\n })\n\n // Progress\n const progress = computed(() => filmGroup.value?.selection_progresses[0])\n const { mutate: updateProgress } = useMutation(UpsertSelectionProgress, { clientId: 'selection', })\n const teamIndex = computed({\n get: () => progress.value?.index || 0,\n set: async (index: number) => {\n if (!filmGroup.value) return\n if (index === undefined) return\n return await updateProgress({\n film_group_id: filmGroup.value.id,\n index,\n })\n }\n })\n const currentTeam = computed(() => {\n return filmGroup.value?.teams[teamIndex.value].team\n })\n\n // Metrics\n const teamMetricEnabled = computed(() => (teamId: number, awardId: number) => {\n const award = _.find(awards.value, { id: awardId })\n if (award?.max_nominations! < 0) return true\n\n const team = _.find(filmGroup.value?.teams, { team: { id: teamId } })\n const nominations = _.find(team?.team.award_nominations, { award: { id: awardId } })\n return !!nominations\n })\n const getTeamMetric = computed(() => (teamId: number, awardId: number) => {\n const team = _.find(filmGroup.value?.teams, { team: { id: teamId } })\n const metric = _.find(team?.team.selection_metrics, { award_id: awardId })\n return metric ? metric.value : 0\n })\n const { mutate: updateMetric } = useMutation(UpsertSelectionMetric, {\n clientId: 'selection',\n update: (cache, { data: result }) => {\n if (!result) return\n\n let data = cache.readQuery({\n query: SelectionFilmGroups, variables: {\n ffid: openFeature.getNumber('current_film_festival'),\n poster: openFeature.getObject('asset_type_ids').poster,\n }\n })\n data = {\n ...data!,\n filmGroups: data?.filmGroups.map((fg) => {\n return {\n ...fg,\n teams: fg.teams.map((t) => {\n if (t.team.id != result.insert_selection_metrics_one?.team_id) return t\n if (_.find(t.team.selection_metrics, { award_id: result.insert_selection_metrics_one?.award_id })) return t\n\n return {\n ...t,\n team: {\n ...t.team,\n selection_metrics: [\n ...t.team.selection_metrics,\n result.insert_selection_metrics_one!\n ]\n }\n }\n })\n }\n })!\n }\n\n cache.writeQuery({ query: SelectionFilmGroups, data })\n },\n })\n const setTeamMetric = computed(() => async (team_id: number, award_id: number, value: number) => {\n return await updateMetric({ team_id, award_id, value })\n })\n\n // Metric Progress\n const metricProgress = computed(() => {\n return _.chain(filmGroups.value)\n .keyBy('id')\n .mapValues((fg) => {\n return _.meanBy(fg.teams, (t) => {\n const na = _.uniqBy(t.team.award_nominations, n => n.award?.id).length + 1\n return (t.team.selection_metrics_aggregate.aggregate?.count || 0) / na\n })\n })\n .value()\n })\n const metricFilmProgress = computed(() => (filmGroupId: number, teamId: number) => {\n const filmGroup = _.find(filmGroups.value, { id: filmGroupId })\n const team = _.find(filmGroup?.teams, { team: { id: teamId } })\n const na = _.uniqBy(team?.team.award_nominations, n => n.award?.id).length + 1\n return (team?.team.selection_metrics_aggregate.aggregate?.count || 0) / na\n })\n\n return {\n filmGroups,\n awards,\n filmGroup,\n teamIndex,\n currentTeam,\n teamMetricEnabled,\n getTeamMetric,\n setTeamMetric,\n metricProgress,\n metricFilmProgress,\n refetch\n }\n})\n\nconst SelectionFilmGroups = gql(`query SelectionFilmGroups($ffid: numeric!, $poster: numeric!) {\n filmGroups: film_groups(where: { film_festival_id: { _eq: $ffid }, type: { _eq: \"selection\" } }) {\n id\n name\n teams(order_by: { sort: asc }) {\n id\n team {\n id\n name\n team_number\n film_name\n genre\n description\n poster: assets(\n where: { asset_type_id: { _eq: $poster } }\n order_by: { created: desc }\n limit: 1\n ) {\n id\n file_name\n }\n film {\n id\n mux_playback_id\n mux_thumbnail_time\n }\n studio {\n id\n name\n }\n selection_metrics_aggregate(where: {value: {_gt: 0}}) {\n aggregate {\n count\n }\n }\n selection_metrics {\n id\n award_id\n value\n }\n award_nominations(order_by: {award: {name: asc}}) {\n id\n award {\n id\n name\n }\n assets(limit: 1) {\n id\n file_name\n }\n membership {\n id\n registration {\n id\n first_name\n last_name\n }\n }\n }\n }\n }\n selection_progresses {\n id\n index\n seek\n }\n }\n awards(where: { max_nominations: { _neq: 0 } }, order_by: { name: asc }) {\n id\n name\n description\n max_nominations\n }\n}`)\n\nconst UpsertSelectionProgress = gql(`mutation UpsertSelectionProgress($film_group_id: Int!, $index: Int!) {\n insert_selection_progress_one(\n object: { film_group_id: $film_group_id, index: $index, seek: 0 }\n on_conflict: {\n constraint: selection_progress_film_group_id_real_user_id_key\n update_columns: [index, seek]\n }\n ) {\n id index seek\n }\n}`)\n\nconst UpsertSelectionMetric = gql(`mutation UpsertSelectionMetric(\n $award_id: numeric!\n $team_id: numeric!\n $value: Int!\n) {\n insert_selection_metrics_one(\n object: { award_id: $award_id, team_id: $team_id, value: $value }\n on_conflict: {\n constraint: selection_metrics_real_user_id_team_id_award_id_key\n update_columns: value\n }\n ) {\n id\n team_id\n award_id\n value\n team {\n id\n selection_metrics_aggregate(where: {value: {_gt: 0}}) {\n aggregate {\n count\n }\n }\n }\n }\n}`)\n"],"names":["useSelectionCommittee","defineStore","openFeature","useOpenFeature","result","refetch","useQuery","SelectionFilmGroups","filmGroups","computed","_a","awards","filmGroup","route","useRoute","fg","progress","updateProgress","useMutation","UpsertSelectionProgress","teamIndex","index","currentTeam","teamMetricEnabled","teamId","awardId","award","_","team","getTeamMetric","metric","updateMetric","UpsertSelectionMetric","cache","data","t","setTeamMetric","team_id","award_id","value","metricProgress","na","metricFilmProgress","filmGroupId","n","gql"],"mappings":"0JAKa,MAAAA,EAAwBC,EAAY,qBAAsB,IAAM,CAC3E,MA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