{ "version": 3, "sources": ["../../import_data/import_data_state.ts"], "sourcesContent": ["import {action, observable, runInAction, makeObservable} from \"mobx\"\nimport {call_function} from \"@cling/lib.shared.faas\"\nimport {\n EngagementType,\n ImportDataRequest,\n ImportDataResponse,\n JobStatus,\n QueryImportDataJobRequest,\n QueryImportDataJobResponse,\n} from \"@cling/lib.shared.model\"\nimport {Snackbar} from \"@cling/lib.web.mdc\"\nimport {i18n} from \"@cling/lib.web.i18n\"\nimport {report_user_engagement} from \"@cling/lib.web.analytics\"\n\nclass ImportDataState {\n job_status?: JobStatus = undefined\n progress_value = 0\n progress_max = 0\n progress_interval: any\n private job_id?: string\n private timeout_id: any\n\n start_import = async (req: ImportDataRequest) => {\n this.reset()\n this.progress_interval = setInterval(this.inc_fake_progress, 100)\n this.job_status = JobStatus.job_pending\n this.job_id = (await call_function(req, ImportDataResponse)).job_id\n this.timeout_id = setTimeout(this.update, 773)\n report_user_engagement(EngagementType.import_data)\n }\n\n inc_fake_progress = () => {\n this.progress_value += (this.progress_max - this.progress_value) / 80\n }\n\n constructor() {\n makeObservable(this, {\n job_status: observable,\n progress_value: observable,\n progress_max: observable,\n start_import: action,\n inc_fake_progress: action,\n reset: action,\n close_toast: action,\n })\n }\n\n reset() {\n clearInterval(this.progress_interval)\n clearTimeout(this.timeout_id)\n this.progress_value = 0\n this.progress_max = 100\n this.job_status = undefined\n }\n\n close_toast = () => {\n this.reset()\n }\n\n private update = async () => {\n if (!this.job_id) {\n return\n }\n let cling_error_code\n let num_succeeded = 0\n let num_failed = 0\n try {\n const {job} = await call_function(\n new QueryImportDataJobRequest({job_id: this.job_id}),\n QueryImportDataJobResponse,\n )\n if (this.job_status !== job.status) {\n runInAction(() => {\n this.job_status = job.status\n cling_error_code = job.cling_error_code\n num_succeeded = job.num_succeeded\n num_failed = job.num_failed\n })\n }\n } finally {\n if (\n this.job_status === JobStatus.job_pending ||\n this.job_status === JobStatus.job_running\n ) {\n this.timeout_id = setTimeout(this.update, 733)\n } else {\n this.reset()\n if (cling_error_code || (num_succeeded === 0 && num_failed > 0)) {\n if (cling_error_code) {\n Snackbar.show_message(\n i18n.cling_error_code_msg(\n cling_error_code,\n i18n.sorry_could_not_import_data,\n ),\n )\n } else {\n Snackbar.show_message(i18n.sorry_could_not_import_data)\n }\n } else {\n Snackbar.show_message(i18n.num_notes_imported({num_succeeded, num_failed}))\n }\n }\n }\n }\n}\n\nexport const import_data_state = new ImportDataState()\n"], "mappings": "8PAcA,IAAMA,EAAN,MAAMA,CAAgB,CAqBlB,aAAc,CApBdC,EAAA,mBACAA,EAAA,sBAAiB,GACjBA,EAAA,oBAAe,GACfA,EAAA,0BACAA,EAAA,KAAQ,UACRA,EAAA,KAAQ,cAERA,EAAA,oBAAeC,EAAA,MAAOC,GAA2B,CAC7C,KAAK,MAAM,EACX,KAAK,kBAAoB,YAAY,KAAK,kBAAmB,GAAG,EAChE,KAAK,WAAa,EAClB,KAAK,QAAU,MAAMC,EAAcD,EAAKE,CAAkB,GAAG,OAC7D,KAAK,WAAa,WAAW,KAAK,OAAQ,GAAG,EAC7CC,IAAiD,CACrD,EAPe,iBASfL,EAAA,yBAAoBC,EAAA,IAAM,CACtB,KAAK,iBAAmB,KAAK,aAAe,KAAK,gBAAkB,EACvE,EAFoB,sBAwBpBD,EAAA,mBAAcC,EAAA,IAAM,CAChB,KAAK,MAAM,CACf,EAFc,gBAIdD,EAAA,KAAQ,SAASC,EAAA,SAAY,CACzB,GAAI,CAAC,KAAK,OACN,OAEJ,IAAIK,EACAC,EAAgB,EAChBC,EAAa,EACjB,GAAI,CACA,GAAM,CAAC,IAAAC,CAAG,EAAI,MAAMN,EAChB,IAAIO,EAA0B,CAAC,OAAQ,KAAK,MAAM,CAAC,EACnDC,CACJ,EACI,KAAK,aAAeF,EAAI,QACxBG,EAAY,IAAM,CACd,KAAK,WAAaH,EAAI,OACtBH,EAAmBG,EAAI,iBACvBF,EAAgBE,EAAI,cACpBD,EAAaC,EAAI,UACrB,CAAC,CAET,QAAE,CAEM,KAAK,aAAe,GACpB,KAAK,aAAe,EAEpB,KAAK,WAAa,WAAW,KAAK,OAAQ,GAAG,GAE7C,KAAK,MAAM,EACPH,GAAqBC,IAAkB,GAAKC,EAAa,EACrDF,EACAO,EAAS,aACLC,EAAK,qBACDR,EACAQ,EAAK,2BACT,CACJ,EAEAD,EAAS,aAAaC,EAAK,2BAA2B,EAG1DD,EAAS,aAAaC,EAAK,mBAAmB,CAAC,cAAAP,EAAe,WAAAC,CAAU,CAAC,CAAC,EAGtF,CACJ,EA5CiB,WAvBbO,EAAe,KAAM,CACjB,WAAYC,EACZ,eAAgBA,EAChB,aAAcA,EACd,aAAcC,EACd,kBAAmBA,EACnB,MAAOA,EACP,YAAaA,CACjB,CAAC,CACL,CAEA,OAAQ,CACJ,cAAc,KAAK,iBAAiB,EACpC,aAAa,KAAK,UAAU,EAC5B,KAAK,eAAiB,EACtB,KAAK,aAAe,IACpB,KAAK,WAAa,MACtB,CAmDJ,EA1FsBhB,EAAAF,EAAA,mBAAtB,IAAMmB,EAANnB,EA4FaoB,EAAoB,IAAID", "names": ["_ImportDataState", "__publicField", "__name", "req", "call_function", "ImportDataResponse", "report_user_engagement", "cling_error_code", "num_succeeded", "num_failed", "job", "QueryImportDataJobRequest", "QueryImportDataJobResponse", "runInAction", "Snackbar", "i18n", "makeObservable", "observable", "action", "ImportDataState", "import_data_state"] }