touchstudy-core 0.1.21 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -140,6 +140,7 @@ var AuthenticationMessage;
140
140
  Role["Student"] = "Student";
141
141
  Role["Teacher"] = "Teacher";
142
142
  Role["Admin"] = "Admin";
143
+ Role["AcademyAdmin"] = "AcademyAdmin";
143
144
  })(exports.Role || (exports.Role = {}));
144
145
 
145
146
  // A type of promise-like that resolves synchronously and supports only one observer
@@ -1042,6 +1043,7 @@ var CommonDialog = function CommonDialog(_ref) {
1042
1043
  _ref$isShowHeader = _ref.isShowHeader,
1043
1044
  isShowHeader = _ref$isShowHeader === void 0 ? true : _ref$isShowHeader,
1044
1045
  titleClassName = _ref.titleClassName,
1046
+ minWidth = _ref.minWidth,
1045
1047
  onClose = _ref.onClose;
1046
1048
  return React__default.createElement(material.Dialog, {
1047
1049
  open: open,
@@ -1054,7 +1056,8 @@ var CommonDialog = function CommonDialog(_ref) {
1054
1056
  },
1055
1057
  PaperProps: {
1056
1058
  sx: {
1057
- overflowY: "unset"
1059
+ overflowY: "unset",
1060
+ minWidth: minWidth
1058
1061
  }
1059
1062
  }
1060
1063
  }, isShowHeader ? React__default.createElement(React.Fragment, null, React__default.createElement(material.DialogTitle, {
@@ -1455,6 +1458,17 @@ var parent_phone_number = "학부모 전화번호";
1455
1458
  var update_textbook_title = "교과서 제목 업데이트";
1456
1459
  var invalid_weekly_day_time = "주간 요일 시간이 잘못되었습니다";
1457
1460
  var no_image = "이미지 없음";
1461
+ var school_name = "학교 이름";
1462
+ var phone_number = "전화번호";
1463
+ var major = "주요한";
1464
+ var roles = "역할";
1465
+ var searching_for = "검색 중...";
1466
+ var parent_name = "부모님 성함";
1467
+ var users = "사용자";
1468
+ var new_user = "새로운 사용자";
1469
+ var academy_admin = "아카데미 관리자";
1470
+ var switch_academy_admin = "스위치 아카데미 관리자";
1471
+ var there_are_no_lessons_this_week = "이번주는 수업이 없습니다";
1458
1472
  var lang_ko = {
1459
1473
  problem_solving: problem_solving,
1460
1474
  my_story: my_story,
@@ -1697,7 +1711,18 @@ var lang_ko = {
1697
1711
  parent_phone_number: parent_phone_number,
1698
1712
  update_textbook_title: update_textbook_title,
1699
1713
  invalid_weekly_day_time: invalid_weekly_day_time,
1700
- no_image: no_image
1714
+ no_image: no_image,
1715
+ school_name: school_name,
1716
+ phone_number: phone_number,
1717
+ major: major,
1718
+ roles: roles,
1719
+ searching_for: searching_for,
1720
+ parent_name: parent_name,
1721
+ users: users,
1722
+ new_user: new_user,
1723
+ academy_admin: academy_admin,
1724
+ switch_academy_admin: switch_academy_admin,
1725
+ there_are_no_lessons_this_week: there_are_no_lessons_this_week
1701
1726
  };
1702
1727
 
1703
1728
  var problem_solving$1 = "Problem Solving";
@@ -1967,7 +1992,7 @@ var add_new_chapter_to_textbook$1 = "Add new chapter to the textbook";
1967
1992
  var add_new_subchapter_to_parent_chapter$1 = "Add new subchapter to the parent chapter ({{ chapterName }})";
1968
1993
  var add$1 = "Add";
1969
1994
  var add_new_article_to_chapter$1 = "Add new article to the chapter ({{ chapterName }})";
1970
- var score_format$1 = "{{score}}points";
1995
+ var score_format$1 = "{{score}}pts";
1971
1996
  var round$1 = "{{number}} round";
1972
1997
  var number_grade$1 = "Grade {{number}}";
1973
1998
  var print$1 = "Print";
@@ -1978,6 +2003,17 @@ var parent_phone_number$1 = "Parent Phone Number";
1978
2003
  var update_textbook_title$1 = "Update textbook title";
1979
2004
  var invalid_weekly_day_time$1 = "Invalid weekly day time";
1980
2005
  var no_image$1 = "No image";
2006
+ var school_name$1 = "School name";
2007
+ var phone_number$1 = "Phone Number";
2008
+ var major$1 = "Major";
2009
+ var roles$1 = "Roles";
2010
+ var searching_for$1 = "Searching for...";
2011
+ var parent_name$1 = "Parent name";
2012
+ var users$1 = "Users";
2013
+ var new_user$1 = "New user";
2014
+ var academy_admin$1 = "Academy Admin";
2015
+ var switch_academy_admin$1 = "Switch Academy Admin";
2016
+ var there_are_no_lessons_this_week$1 = "There are no lessons this week";
1981
2017
  var lang_en = {
1982
2018
  problem_solving: problem_solving$1,
1983
2019
  my_story: my_story$1,
@@ -2254,7 +2290,18 @@ var lang_en = {
2254
2290
  parent_phone_number: parent_phone_number$1,
2255
2291
  update_textbook_title: update_textbook_title$1,
2256
2292
  invalid_weekly_day_time: invalid_weekly_day_time$1,
2257
- no_image: no_image$1
2293
+ no_image: no_image$1,
2294
+ school_name: school_name$1,
2295
+ phone_number: phone_number$1,
2296
+ major: major$1,
2297
+ roles: roles$1,
2298
+ searching_for: searching_for$1,
2299
+ parent_name: parent_name$1,
2300
+ users: users$1,
2301
+ new_user: new_user$1,
2302
+ academy_admin: academy_admin$1,
2303
+ switch_academy_admin: switch_academy_admin$1,
2304
+ there_are_no_lessons_this_week: there_are_no_lessons_this_week$1
2258
2305
  };
2259
2306
 
2260
2307
  i18n.use(reactI18next.initReactI18next).init({
@@ -2439,6 +2486,8 @@ var useSwitchAcademy = function useSwitchAcademy(role, navigate, homeAcademyUrl,
2439
2486
  var _state$common2;
2440
2487
  return state === null || state === void 0 ? void 0 : (_state$common2 = state.common) === null || _state$common2 === void 0 ? void 0 : _state$common2.isReFetchUserAcademies;
2441
2488
  });
2489
+ var _useTranslation = reactI18next.useTranslation(),
2490
+ t = _useTranslation.t;
2442
2491
  var getAcademies = function getAcademies(isLoading) {
2443
2492
  if (isLoading === void 0) {
2444
2493
  isLoading = true;
@@ -2499,7 +2548,7 @@ var useSwitchAcademy = function useSwitchAcademy(role, navigate, homeAcademyUrl,
2499
2548
  });
2500
2549
  }, function (error) {
2501
2550
  var _error$response2, _error$response2$data;
2502
- reactToastify.toast.error((error === null || error === void 0 ? void 0 : (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : (_error$response2$data = _error$response2.data) === null || _error$response2$data === void 0 ? void 0 : _error$response2$data.title) || "Switch academy failed");
2551
+ reactToastify.toast.error((error === null || error === void 0 ? void 0 : (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : (_error$response2$data = _error$response2.data) === null || _error$response2$data === void 0 ? void 0 : _error$response2$data.title) || t("switch_academy_admin"));
2503
2552
  });
2504
2553
  return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4));
2505
2554
  } catch (e) {
@@ -2543,6 +2592,8 @@ var TheAcademyDropdown = function TheAcademyDropdown(_ref) {
2543
2592
  });
2544
2593
  var isAdmin = role === exports.Role.Admin;
2545
2594
  var isSuperAdmin = user && !user.academyDomain && ((_user$roles = user.roles) === null || _user$roles === void 0 ? void 0 : _user$roles.includes(exports.Role.Admin));
2595
+ var _useTranslation = reactI18next.useTranslation(),
2596
+ t = _useTranslation.t;
2546
2597
  var _useState = React.useState(null),
2547
2598
  open = _useState[0],
2548
2599
  setOpen = _useState[1];
@@ -2579,7 +2630,7 @@ var TheAcademyDropdown = function TheAcademyDropdown(_ref) {
2579
2630
  color: "#5458D5",
2580
2631
  minWidth: 150
2581
2632
  }
2582
- }, (selectedAcademy === null || selectedAcademy === void 0 ? void 0 : selectedAcademy.name) || "Switch Academy Admin"), React__default.createElement("div", {
2633
+ }, (selectedAcademy === null || selectedAcademy === void 0 ? void 0 : selectedAcademy.name) || t("switch_academy_admin")), React__default.createElement("div", {
2583
2634
  className: "" + stylesGlobal["switch-icon"]
2584
2635
  }, React__default.createElement(go.GoArrowSwitch, {
2585
2636
  size: 14
@@ -2762,7 +2813,8 @@ var ChatRightItem = function ChatRightItem(_ref) {
2762
2813
  showTimestamp = _ref.showTimestamp,
2763
2814
  isStudent = _ref.isStudent,
2764
2815
  showName = _ref.showName,
2765
- contentType = _ref.contentType;
2816
+ contentType = _ref.contentType,
2817
+ toggleImageDialog = _ref.toggleImageDialog;
2766
2818
  var _useTranslation = reactI18next.useTranslation(),
2767
2819
  t = _useTranslation.t;
2768
2820
  return React__default.createElement("div", null, showTimestamp && React__default.createElement(material.Typography, {
@@ -2790,6 +2842,7 @@ var ChatRightItem = function ChatRightItem(_ref) {
2790
2842
  lineHeight: "16.71px",
2791
2843
  color: "#5458D5"
2792
2844
  }, sender === null || sender === void 0 ? void 0 : sender.fullName)), contentType ? React__default.createElement("img", {
2845
+ onClick: toggleImageDialog,
2793
2846
  src: content,
2794
2847
  style: {
2795
2848
  backgroundRepeat: "no-repeat",
@@ -2819,7 +2872,8 @@ var ChatLeftItem = function ChatLeftItem(_ref) {
2819
2872
  showTimestamp = _ref.showTimestamp,
2820
2873
  isStudent = _ref.isStudent,
2821
2874
  showName = _ref.showName,
2822
- contentType = _ref.contentType;
2875
+ contentType = _ref.contentType,
2876
+ toggleImageDialog = _ref.toggleImageDialog;
2823
2877
  var _useTranslation = reactI18next.useTranslation(),
2824
2878
  t = _useTranslation.t;
2825
2879
  return React__default.createElement("div", null, showTimestamp && React__default.createElement(material.Typography, {
@@ -2861,6 +2915,7 @@ var ChatLeftItem = function ChatLeftItem(_ref) {
2861
2915
  }, t("student")))), React__default.createElement(material.Box, {
2862
2916
  padding: "4px 0px"
2863
2917
  }), contentType ? React__default.createElement("img", {
2918
+ onClick: toggleImageDialog,
2864
2919
  src: content,
2865
2920
  style: {
2866
2921
  backgroundRepeat: "no-repeat",
@@ -2880,6 +2935,115 @@ var ChatLeftItem = function ChatLeftItem(_ref) {
2880
2935
  }, content))));
2881
2936
  };
2882
2937
 
2938
+ var ImageDetailDialog = function ImageDetailDialog(_ref) {
2939
+ var open = _ref.open,
2940
+ toggleDialog = _ref.toggleDialog,
2941
+ content = _ref.content,
2942
+ downloadFile = _ref.downloadFile;
2943
+ var _useTranslation = reactI18next.useTranslation(),
2944
+ t = _useTranslation.t;
2945
+ return React__default.createElement(CommonDialog, {
2946
+ open: open,
2947
+ onClose: toggleDialog,
2948
+ size: "sm",
2949
+ title: t("image")
2950
+ }, React__default.createElement(material.DialogContent, {
2951
+ sx: {
2952
+ overflowY: "unset"
2953
+ }
2954
+ }, React__default.createElement(material.Stack, null, React__default.createElement(material.Stack, {
2955
+ display: "flex",
2956
+ justifyContent: "center",
2957
+ alignItems: "center"
2958
+ }, React__default.createElement("img", {
2959
+ src: content,
2960
+ style: {
2961
+ width: "500px",
2962
+ height: "500px",
2963
+ position: "relative",
2964
+ objectFit: "cover"
2965
+ }
2966
+ })), React__default.createElement(material.Button, {
2967
+ sx: {
2968
+ margin: "10px 0"
2969
+ },
2970
+ variant: "outlined",
2971
+ fullWidth: true,
2972
+ onClick: function onClick() {
2973
+ return downloadFile(content);
2974
+ }
2975
+ }, t("download")))));
2976
+ };
2977
+
2978
+ var CONVERSATION_URL = BASE_URL + "/api/conversation";
2979
+ var apiAddMessage = function apiAddMessage(conversationId, message) {
2980
+ return api.post(CONVERSATION_URL + "/" + conversationId + "/messages", message);
2981
+ };
2982
+ var getMessagesByConversation = function getMessagesByConversation(conversationId, filter) {
2983
+ return api.get(CONVERSATION_URL + "/" + conversationId + "/messages", {
2984
+ params: filter
2985
+ });
2986
+ };
2987
+ var updateLastTimeReadConversation = function updateLastTimeReadConversation(conversationId) {
2988
+ return api.put(CONVERSATION_URL + "/" + conversationId);
2989
+ };
2990
+ var completeConversation = function completeConversation(conversationId) {
2991
+ return api.post(CONVERSATION_URL + "/" + conversationId + "/finish");
2992
+ };
2993
+ var apiUploadImageFile = function apiUploadImageFile(file) {
2994
+ return apiUpload.post(BASE_URL + "/api/file/images", file);
2995
+ };
2996
+
2997
+ var FileSaver_min = createCommonjsModule(function (module, exports) {
2998
+ (function(a,b){b();})(commonjsGlobal,function(){function b(a,b){return "undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(a,b,c){var d=new XMLHttpRequest;d.open("GET",a),d.responseType="blob",d.onload=function(){g(d.response,b,c);},d.onerror=function(){console.error("could not download file");},d.send();}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send();}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"));}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b);}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof commonjsGlobal&&commonjsGlobal.global===commonjsGlobal?commonjsGlobal:void 0,a=f.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),g=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype&&!a?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href);},4E4),setTimeout(function(){e(j);},0));}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else {var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i);});}}:function(b,d,e,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),"string"==typeof b)return c(b,d,e);var h="application/octet-stream"===b.type,i=/constructor/i.test(f.HTMLElement)||f.safari,j=/CriOS\/[\d]+/.test(navigator.userAgent);if((j||h&&i||a)&&"undefined"!=typeof FileReader){var k=new FileReader;k.onloadend=function(){var a=k.result;a=j?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=a:location=a,g=null;},k.readAsDataURL(b);}else {var l=f.URL||f.webkitURL,m=l.createObjectURL(b);g?g.location=m:location.href=m,g=null,setTimeout(function(){l.revokeObjectURL(m);},4E4);}});f.saveAs=g.saveAs=g,(module.exports=g);});
2999
+
3000
+
3001
+ });
3002
+
3003
+ var useDialog = function useDialog() {
3004
+ var _useState = React.useState(false),
3005
+ openConfirmDialog = _useState[0],
3006
+ setOpenConfirmDialog = _useState[1];
3007
+ var toggleConfirmDialog = function toggleConfirmDialog() {
3008
+ setOpenConfirmDialog(function (state) {
3009
+ return !state;
3010
+ });
3011
+ };
3012
+ var handleConfirm = function handleConfirm(conversationId) {
3013
+ try {
3014
+ var _temp2 = function _temp2() {
3015
+ setLoading(false);
3016
+ };
3017
+ setLoading(true);
3018
+ var _temp = _catch(function () {
3019
+ return Promise.resolve(completeConversation(conversationId)).then(function () {
3020
+ toggleConfirmDialog();
3021
+ reactToastify.toast.success("Complete conversation success");
3022
+ });
3023
+ }, function () {
3024
+ reactToastify.toast.error("Failed to complete conversation");
3025
+ });
3026
+ return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
3027
+ } catch (e) {
3028
+ return Promise.reject(e);
3029
+ }
3030
+ };
3031
+ var downloadFile = function downloadFile(content) {
3032
+ try {
3033
+ FileSaver_min.saveAs(content, "image.png");
3034
+ return Promise.resolve();
3035
+ } catch (e) {
3036
+ return Promise.reject(e);
3037
+ }
3038
+ };
3039
+ return {
3040
+ openConfirmDialog: openConfirmDialog,
3041
+ toggleConfirmDialog: toggleConfirmDialog,
3042
+ handleConfirm: handleConfirm,
3043
+ downloadFile: downloadFile
3044
+ };
3045
+ };
3046
+
2883
3047
  (function (ChatItemType) {
2884
3048
  ChatItemType[ChatItemType["Default"] = 0] = "Default";
2885
3049
  ChatItemType[ChatItemType["Exam"] = 1] = "Exam";
@@ -2887,7 +3051,20 @@ var ChatLeftItem = function ChatLeftItem(_ref) {
2887
3051
  })(exports.ChatItemType || (exports.ChatItemType = {}));
2888
3052
  var ChatItem = function ChatItem(props) {
2889
3053
  var isMe = props.isMe;
2890
- return React__default.createElement(React.Fragment, null, isMe ? React__default.createElement(ChatRightItem, Object.assign({}, props)) : React__default.createElement(ChatLeftItem, Object.assign({}, props)));
3054
+ var _useDialog = useDialog(),
3055
+ openConfirmDialog = _useDialog.openConfirmDialog,
3056
+ toggleConfirmDialog = _useDialog.toggleConfirmDialog,
3057
+ downloadFile = _useDialog.downloadFile;
3058
+ return React__default.createElement(React.Fragment, null, isMe ? React__default.createElement(ChatRightItem, Object.assign({}, props, {
3059
+ toggleImageDialog: toggleConfirmDialog
3060
+ })) : React__default.createElement(ChatLeftItem, Object.assign({}, props, {
3061
+ toggleImageDialog: toggleConfirmDialog
3062
+ })), React__default.createElement(ImageDetailDialog, {
3063
+ open: openConfirmDialog,
3064
+ toggleDialog: toggleConfirmDialog,
3065
+ content: props.content || "",
3066
+ downloadFile: downloadFile
3067
+ }));
2891
3068
  };
2892
3069
 
2893
3070
  var MessageSortBy;
@@ -3153,57 +3330,6 @@ var iconChecked = function iconChecked(_ref) {
3153
3330
  }));
3154
3331
  };
3155
3332
 
3156
- var CONVERSATION_URL = BASE_URL + "/api/conversation";
3157
- var apiAddMessage = function apiAddMessage(conversationId, message) {
3158
- return api.post(CONVERSATION_URL + "/" + conversationId + "/messages", message);
3159
- };
3160
- var getMessagesByConversation = function getMessagesByConversation(conversationId, filter) {
3161
- return api.get(CONVERSATION_URL + "/" + conversationId + "/messages", {
3162
- params: filter
3163
- });
3164
- };
3165
- var completeConversation = function completeConversation(conversationId) {
3166
- return api.post(CONVERSATION_URL + "/" + conversationId + "/finish");
3167
- };
3168
- var apiUploadImageFile = function apiUploadImageFile(file) {
3169
- return apiUpload.post(BASE_URL + "/api/file/images", file);
3170
- };
3171
-
3172
- var useDialog = function useDialog() {
3173
- var _useState = React.useState(false),
3174
- openConfirmDialog = _useState[0],
3175
- setOpenConfirmDialog = _useState[1];
3176
- var toggleConfirmDialog = function toggleConfirmDialog() {
3177
- setOpenConfirmDialog(function (state) {
3178
- return !state;
3179
- });
3180
- };
3181
- var handleConfirm = function handleConfirm(conversationId) {
3182
- try {
3183
- var _temp2 = function _temp2() {
3184
- setLoading(false);
3185
- };
3186
- setLoading(true);
3187
- var _temp = _catch(function () {
3188
- return Promise.resolve(completeConversation(conversationId)).then(function () {
3189
- toggleConfirmDialog();
3190
- reactToastify.toast.success("Complete conversation success");
3191
- });
3192
- }, function () {
3193
- reactToastify.toast.error("Failed to complete conversation");
3194
- });
3195
- return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
3196
- } catch (e) {
3197
- return Promise.reject(e);
3198
- }
3199
- };
3200
- return {
3201
- openConfirmDialog: openConfirmDialog,
3202
- toggleConfirmDialog: toggleConfirmDialog,
3203
- handleConfirm: handleConfirm
3204
- };
3205
- };
3206
-
3207
3333
  var ChatHeader = function ChatHeader(_ref) {
3208
3334
  var fullName = _ref.fullName,
3209
3335
  examTitle = _ref.examTitle,
@@ -3418,6 +3544,10 @@ var ChatContainer = function ChatContainer(_ref) {
3418
3544
  if (scrollTop <= scrollOffset) {
3419
3545
  return Promise.resolve(onReachTop === null || onReachTop === void 0 ? void 0 : onReachTop()).then(function (isSuccessLoad) {
3420
3546
  if (isSuccessLoad) {
3547
+ var _listItemRef$current, _listItemRef$current$;
3548
+ (_listItemRef$current = listItemRef.current) === null || _listItemRef$current === void 0 ? void 0 : (_listItemRef$current$ = _listItemRef$current.lastElementChild) === null || _listItemRef$current$ === void 0 ? void 0 : _listItemRef$current$.scrollIntoView({
3549
+ behavior: "smooth"
3550
+ });
3421
3551
  listRef.current.scrollTop = listRef.current.scrollHeight - scrollHeight;
3422
3552
  }
3423
3553
  });
@@ -3435,24 +3565,20 @@ var ChatContainer = function ChatContainer(_ref) {
3435
3565
  }
3436
3566
  };
3437
3567
  React.useEffect(function () {
3438
- var _listRef$current, _chatListProps$messag, _listRef$current3;
3568
+ var _listRef$current, _chatListProps$messag, _listRef$current2;
3439
3569
  scrollRef.current && clearTimeout(scrollRef.current);
3440
3570
  addEventTimeout.current && clearTimeout(addEventTimeout.current);
3441
3571
  (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.removeEventListener("scroll", handleScroll);
3442
3572
  if (isScrollToEnd && !isLoading && (_chatListProps$messag = chatListProps.messages) !== null && _chatListProps$messag !== void 0 && _chatListProps$messag.length) {
3443
- var _listItemRef$current, _listItemRef$current$;
3444
- (_listItemRef$current = listItemRef.current) === null || _listItemRef$current === void 0 ? void 0 : (_listItemRef$current$ = _listItemRef$current.lastElementChild) === null || _listItemRef$current$ === void 0 ? void 0 : _listItemRef$current$.scrollIntoView({
3573
+ var _listItemRef$current2, _listItemRef$current3;
3574
+ (_listItemRef$current2 = listItemRef.current) === null || _listItemRef$current2 === void 0 ? void 0 : (_listItemRef$current3 = _listItemRef$current2.lastElementChild) === null || _listItemRef$current3 === void 0 ? void 0 : _listItemRef$current3.scrollIntoView({
3445
3575
  behavior: "smooth"
3446
3576
  });
3447
3577
  onEndScrollToEnd === null || onEndScrollToEnd === void 0 ? void 0 : onEndScrollToEnd();
3448
- addEventTimeout.current = setTimeout(function () {
3449
- var _listRef$current2;
3450
- (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.addEventListener("scroll", handleScroll);
3451
- }, 800);
3452
- } else (_listRef$current3 = listRef.current) === null || _listRef$current3 === void 0 ? void 0 : _listRef$current3.addEventListener("scroll", handleScroll);
3578
+ } else (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.addEventListener("scroll", handleScroll);
3453
3579
  return function () {
3454
- var _listRef$current4;
3455
- (_listRef$current4 = listRef.current) === null || _listRef$current4 === void 0 ? void 0 : _listRef$current4.removeEventListener("scroll", handleScroll);
3580
+ var _listRef$current3;
3581
+ (_listRef$current3 = listRef.current) === null || _listRef$current3 === void 0 ? void 0 : _listRef$current3.removeEventListener("scroll", handleScroll);
3456
3582
  scrollRef.current && clearTimeout(scrollRef.current);
3457
3583
  addEventTimeout.current && clearTimeout(addEventTimeout.current);
3458
3584
  };
@@ -3502,14 +3628,16 @@ var useMessageList = function useMessageList() {
3502
3628
  var _temp = _catch(function () {
3503
3629
  var filter = _extends({}, messageFilter);
3504
3630
  return Promise.resolve(getMessagesByConversation(conversationId, filter)).then(function (res) {
3505
- setMessages(function (prev) {
3506
- var _res$data$items;
3507
- return [].concat((_res$data$items = res.data.items) === null || _res$data$items === void 0 ? void 0 : _res$data$items.reverse(), prev);
3508
- });
3509
- setMessageFilter(function (prev) {
3510
- return _extends({}, prev, {
3511
- totalItems: res.data.totalItems,
3512
- totalPages: res.data.totalPages
3631
+ return Promise.resolve(updateLastTimeReadConversation(conversationId)).then(function () {
3632
+ setMessages(function (prev) {
3633
+ var _res$data$items;
3634
+ return [].concat((_res$data$items = res.data.items) === null || _res$data$items === void 0 ? void 0 : _res$data$items.reverse(), prev);
3635
+ });
3636
+ setMessageFilter(function (prev) {
3637
+ return _extends({}, prev, {
3638
+ totalItems: res.data.totalItems,
3639
+ totalPages: res.data.totalPages
3640
+ });
3513
3641
  });
3514
3642
  });
3515
3643
  });
@@ -3529,28 +3657,30 @@ var useMessageList = function useMessageList() {
3529
3657
  return true;
3530
3658
  };
3531
3659
  var _exit = false;
3532
- if (isLoading) return Promise.resolve();
3660
+ if (isLoading || messageFilter.currentPage === messageFilter.totalPages) return Promise.resolve();
3533
3661
  var filter = _extends({}, messageFilter, {
3534
3662
  currentPage: ((messageFilter === null || messageFilter === void 0 ? void 0 : messageFilter.currentPage) || 1) + 1
3535
3663
  });
3536
- setMessageFilter(filter);
3537
3664
  setLoading(true);
3538
3665
  var _temp3 = _catch(function () {
3539
3666
  return Promise.resolve(getMessagesByConversation(conversationId, filter)).then(function (res) {
3540
- setMessages(function (prev) {
3541
- var _res$data$items2;
3542
- var data = [].concat((_res$data$items2 = res.data.items) === null || _res$data$items2 === void 0 ? void 0 : _res$data$items2.reverse(), prev);
3543
- var dataFilter = new Set(data);
3544
- return Array.from(dataFilter);
3545
- });
3546
- if (res.data.items) {
3547
- setMessageFilter(function (prev) {
3548
- return _extends({}, prev, {
3549
- totalItems: res.data.totalItems,
3550
- totalPages: res.data.totalPages
3667
+ return Promise.resolve(updateLastTimeReadConversation(conversationId)).then(function () {
3668
+ if (res.data.items.length) {
3669
+ setMessages(function (prev) {
3670
+ var _res$data$items2;
3671
+ var data = [].concat((_res$data$items2 = res.data.items) === null || _res$data$items2 === void 0 ? void 0 : _res$data$items2.reverse(), prev);
3672
+ var dataFilter = new Set(data);
3673
+ return Array.from(dataFilter);
3551
3674
  });
3552
- });
3553
- }
3675
+ setMessageFilter(function (prev) {
3676
+ return _extends({}, prev, {
3677
+ totalItems: res.data.totalItems,
3678
+ totalPages: res.data.totalPages,
3679
+ currentPage: res.data.page
3680
+ });
3681
+ });
3682
+ }
3683
+ });
3554
3684
  });
3555
3685
  }, function () {
3556
3686
  reactToastify.toast.error("Fail to fetch data!");
@@ -3663,34 +3793,26 @@ var useChatContainer = function useChatContainer(props) {
3663
3793
  }
3664
3794
  };
3665
3795
  var handleUploadImage = function handleUploadImage(file) {
3666
- try {
3667
- console.log({
3668
- file: file
3669
- });
3670
- if (!file) return Promise.resolve();
3671
- return Promise.resolve(_finally(function () {
3672
- return _catch(function () {
3673
- var formData = new FormData();
3674
- formData.append("upload", file);
3675
- return Promise.resolve(apiUploadImageFile(formData)).then(function (res) {
3676
- var _res$data;
3677
- setSelectedFile({
3678
- content: res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.url
3679
- });
3680
- });
3681
- }, function (error) {
3682
- var _error$response2;
3683
- setMessages(function (state) {
3684
- return [].concat(state.filter(function (i) {
3685
- return (i === null || i === void 0 ? void 0 : i.id) !== 0;
3686
- }));
3796
+ return file ? Promise.resolve(_finally(function () {
3797
+ return _catch(function () {
3798
+ var formData = new FormData();
3799
+ formData.append("upload", file);
3800
+ return Promise.resolve(apiUploadImageFile(formData)).then(function (res) {
3801
+ var _res$data;
3802
+ setSelectedFile({
3803
+ content: res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.url
3687
3804
  });
3688
- reactToastify.toast.error((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data);
3689
3805
  });
3690
- }, function () {}));
3691
- } catch (e) {
3692
- return Promise.reject(e);
3693
- }
3806
+ }, function (error) {
3807
+ var _error$response2;
3808
+ setMessages(function (state) {
3809
+ return [].concat(state.filter(function (i) {
3810
+ return (i === null || i === void 0 ? void 0 : i.id) !== 0;
3811
+ }));
3812
+ });
3813
+ reactToastify.toast.error((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data);
3814
+ });
3815
+ }, function () {})) : Promise.resolve();
3694
3816
  };
3695
3817
  var handleChangeInput = function handleChangeInput(text) {
3696
3818
  setMessage({
@@ -3704,6 +3826,14 @@ var useChatContainer = function useChatContainer(props) {
3704
3826
  return [].concat(state, [data]);
3705
3827
  });
3706
3828
  };
3829
+ var handleNewConversation = function handleNewConversation(data) {
3830
+ if (!data) return;
3831
+ var item = JSON.parse(data);
3832
+ setScrollToEnd(true);
3833
+ setMessages(function (state) {
3834
+ return [].concat(state, [item]);
3835
+ });
3836
+ };
3707
3837
  var handleCompletedConversation = function handleCompletedConversation(data) {
3708
3838
  if (!data) return;
3709
3839
  setSelectedConversation(JSON.parse(data));
@@ -3720,8 +3850,10 @@ var useChatContainer = function useChatContainer(props) {
3720
3850
  setSelectedFile(null);
3721
3851
  };
3722
3852
  var cleanupPusher = function cleanupPusher() {
3723
- var _pusher$current;
3853
+ var _pusher$current, _pusher$current2, _pusher$current3;
3724
3854
  (_pusher$current = pusher.current) === null || _pusher$current === void 0 ? void 0 : _pusher$current.unbind("new-message-event", handleNewMessageSent);
3855
+ (_pusher$current2 = pusher.current) === null || _pusher$current2 === void 0 ? void 0 : _pusher$current2.unbind("completed-conversation-event", handleCompletedConversation);
3856
+ (_pusher$current3 = pusher.current) === null || _pusher$current3 === void 0 ? void 0 : _pusher$current3.unbind("new-conversation-event", handleNewConversation);
3725
3857
  channelName.current && pusher.current && pusher.current.unsubscribe(channelName.current);
3726
3858
  };
3727
3859
  React.useEffect(function () {
@@ -3738,10 +3870,11 @@ var useChatContainer = function useChatContainer(props) {
3738
3870
  }, _headers[AcademyHeaders] = academyDomain, _headers)
3739
3871
  }
3740
3872
  });
3741
- channelName.current = "presence-conversation-channel-" + (selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.id);
3873
+ channelName.current = "presence-conversation-channel-" + (selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.id) + "-" + academyDomain.trim().toUpperCase();
3742
3874
  channel.current = pusher.current.subscribe(channelName.current);
3743
3875
  pusher.current.bind("new-message-event", handleNewMessageSent);
3744
3876
  pusher.current.bind("completed-conversation-event", handleCompletedConversation);
3877
+ pusher.current.bind("new-conversation-event", handleNewConversation);
3745
3878
  }
3746
3879
  return cleanupPusher;
3747
3880
  }, [selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.id, academyDomain]);
@@ -3859,7 +3992,7 @@ var usePusherConversation = function usePusherConversation(onNewMessageConversat
3859
3992
  }, _headers[AcademyHeaders] = academyDomain, _headers)
3860
3993
  }
3861
3994
  });
3862
- channelName.current = "presence-conversation-channel-userId-" + userId;
3995
+ channelName.current = "presence-conversation-channel-userId-" + userId + "-" + academyDomain.trim().toUpperCase();
3863
3996
  channel.current = pusher.current.subscribe(channelName.current);
3864
3997
  channel.current.bind("message-conversation-event", handleNewMessageConversationCreated);
3865
3998
  channel.current.bind("message-conversation-read-event", handleReadMessageConversation);
@@ -4126,12 +4259,16 @@ var ScoreSelector = function ScoreSelector(_ref) {
4126
4259
  isDisabled = _ref.isDisabled;
4127
4260
  var _useTranslation = reactI18next.useTranslation(),
4128
4261
  t = _useTranslation.t;
4129
- var scoreOptions = SCORE_OPTIONS.map(function (i) {
4130
- return {
4131
- label: "" + t(i + "\uC810") + (DEFAULT_SCORE === i ? " (" + t("default").toLocaleLowerCase() + ")" : ""),
4132
- value: i
4133
- };
4134
- });
4262
+ var scoreOptions = React.useMemo(function () {
4263
+ return SCORE_OPTIONS.map(function (i) {
4264
+ return {
4265
+ label: "" + t("score_format", {
4266
+ score: i
4267
+ }) + (DEFAULT_SCORE === i ? " (" + t("default").toLocaleLowerCase() + ")" : ""),
4268
+ value: i
4269
+ };
4270
+ });
4271
+ }, [t]);
4135
4272
  return React__default.createElement(CustomSelect, {
4136
4273
  inputId: id,
4137
4274
  value: value,
@@ -4148,6 +4285,8 @@ var QuestionView = function QuestionView(_ref) {
4148
4285
  isDisabled = _ref.isDisabled,
4149
4286
  onChangeCorrectAnswers = _ref.onChangeCorrectAnswers,
4150
4287
  onChangeScoreAnswer = _ref.onChangeScoreAnswer;
4288
+ var _useTranslation = reactI18next.useTranslation(),
4289
+ t = _useTranslation.t;
4151
4290
  var handleChangeCorrectAnswer = function handleChangeCorrectAnswer(e) {
4152
4291
  return onChangeCorrectAnswers(e.target.value, index);
4153
4292
  };
@@ -4157,7 +4296,9 @@ var QuestionView = function QuestionView(_ref) {
4157
4296
  className: "d-flex flex-grow-1"
4158
4297
  }, React__default.createElement("div", {
4159
4298
  className: styles$1["question-title"] + " me-2 text-nowrap"
4160
- }, "\uBB38\uC81C ", question.questionOrder + 1, "\uBC88"), React__default.createElement(material.FormControl, {
4299
+ }, t("problem_number_question", {
4300
+ number: question.questionOrder + 1
4301
+ })), React__default.createElement(material.FormControl, {
4161
4302
  className: "flex-grow-1 w-100"
4162
4303
  }, React__default.createElement(material.RadioGroup, {
4163
4304
  value: question.correctAnswers[0],
@@ -4178,7 +4319,9 @@ var QuestionView = function QuestionView(_ref) {
4178
4319
  control: React__default.createElement(material.Radio, {
4179
4320
  size: "small"
4180
4321
  }),
4181
- label: i + "\uBC88"
4322
+ label: t("number_question", {
4323
+ number: i
4324
+ })
4182
4325
  });
4183
4326
  })))), React__default.createElement("div", {
4184
4327
  className: "d-flex align-items-center"
@@ -4560,6 +4703,26 @@ var useExamDetailView = function useExamDetailView(props) {
4560
4703
  }))
4561
4704
  }));
4562
4705
  };
4706
+ var handleDeleteArticle = function handleDeleteArticle(article) {
4707
+ if (!exam) return;
4708
+ var removedQuestions = exam.questions.filter(function (i) {
4709
+ return i.article === +article;
4710
+ }).map(function (i) {
4711
+ return i.questionOrder;
4712
+ });
4713
+ var max = Math.max.apply(Math, removedQuestions);
4714
+ var examQuestions = exam.questions.filter(function (i) {
4715
+ return i.article !== +article;
4716
+ }).map(function (i) {
4717
+ return _extends({}, i, {
4718
+ article: i.article > article ? i.article - 1 : i.article,
4719
+ questionOrder: i.questionOrder > max ? i.questionOrder - removedQuestions.length : i.questionOrder
4720
+ });
4721
+ });
4722
+ onChangeExam(_extends({}, exam, {
4723
+ questions: [].concat(examQuestions)
4724
+ }));
4725
+ };
4563
4726
  var handleChangeAnswerCount = function handleChangeAnswerCount(article, newAnswerCount, answerCount) {
4564
4727
  if (!exam) return;
4565
4728
  if (newAnswerCount === answerCount) return;
@@ -4687,10 +4850,10 @@ var useExamDetailView = function useExamDetailView(props) {
4687
4850
  return options;
4688
4851
  }, [exam.duration]);
4689
4852
  React.useEffect(function () {
4690
- onChangeExam(_extends({}, exam, {
4853
+ if ((selectedSubject === null || selectedSubject === void 0 ? void 0 : selectedSubject.id) !== exam.subjectId) onChangeExam(_extends({}, exam, {
4691
4854
  subjectId: (selectedSubject === null || selectedSubject === void 0 ? void 0 : selectedSubject.id) || 0
4692
4855
  }));
4693
- }, [selectedSubject === null || selectedSubject === void 0 ? void 0 : selectedSubject.id]);
4856
+ }, [selectedSubject === null || selectedSubject === void 0 ? void 0 : selectedSubject.id, exam.subjectId]);
4694
4857
  return {
4695
4858
  t: t,
4696
4859
  durationOptions: durationOptions,
@@ -4702,7 +4865,8 @@ var useExamDetailView = function useExamDetailView(props) {
4702
4865
  handleChangeCorrectAnswers: handleChangeCorrectAnswers,
4703
4866
  handleChangeAnswerCount: handleChangeAnswerCount,
4704
4867
  handleChangeQuestionCount: handleChangeQuestionCount,
4705
- handleChangeCategory: handleChangeCategory
4868
+ handleChangeCategory: handleChangeCategory,
4869
+ handleDeleteArticle: handleDeleteArticle
4706
4870
  };
4707
4871
  };
4708
4872
 
@@ -4732,7 +4896,8 @@ var ExamDetailView = function ExamDetailView(_ref) {
4732
4896
  handleChangeCorrectAnswers = _useExamDetailView.handleChangeCorrectAnswers,
4733
4897
  handleChangeAnswerCount = _useExamDetailView.handleChangeAnswerCount,
4734
4898
  handleChangeQuestionCount = _useExamDetailView.handleChangeQuestionCount,
4735
- handleChangeCategory = _useExamDetailView.handleChangeCategory;
4899
+ handleChangeCategory = _useExamDetailView.handleChangeCategory,
4900
+ handleDeleteArticle = _useExamDetailView.handleDeleteArticle;
4736
4901
  return React__default.createElement(material.Grid, {
4737
4902
  container: true,
4738
4903
  spacing: 3,
@@ -4771,7 +4936,7 @@ var ExamDetailView = function ExamDetailView(_ref) {
4771
4936
  }, React__default.createElement("label", {
4772
4937
  className: stylesGlobal["form-label"] + " " + styles$1["question-label"],
4773
4938
  htmlFor: "duration"
4774
- }, " ", t("subject")), React__default.createElement(CustomSelect, {
4939
+ }, t("subject"), " ", selectedSubject === null || selectedSubject === void 0 ? void 0 : selectedSubject.name), React__default.createElement(CustomSelect, {
4775
4940
  inputId: "subject",
4776
4941
  value: selectedSubject === null || selectedSubject === void 0 ? void 0 : selectedSubject.id,
4777
4942
  options: subjectOptions,
@@ -4790,8 +4955,10 @@ var ExamDetailView = function ExamDetailView(_ref) {
4790
4955
  onChangeAnswerCount: handleChangeAnswerCount,
4791
4956
  onChangeCorrectAnswers: handleChangeCorrectAnswers,
4792
4957
  onChangeScoreAnswer: handleChangeScoreAnswer,
4958
+ onDelete: handleDeleteArticle,
4793
4959
  isDisabled: isDisabled,
4794
- selectedSubject: selectedSubject
4960
+ selectedSubject: selectedSubject,
4961
+ isDeletable: examGroupByArticle.length > 1
4795
4962
  })));
4796
4963
  }), React__default.createElement(material.Grid, {
4797
4964
  item: true,
@@ -7299,7 +7466,12 @@ function CreateNewQuestionDialog(_ref) {
7299
7466
  t = _useTranslation.t;
7300
7467
  return React__default.createElement(material.Dialog, {
7301
7468
  onClose: toggleCreateQuestion,
7302
- open: openCreateQuestionDialog
7469
+ open: openCreateQuestionDialog,
7470
+ PaperProps: {
7471
+ sx: {
7472
+ minWidth: "363px"
7473
+ }
7474
+ }
7303
7475
  }, React__default.createElement(DialogTitle, {
7304
7476
  id: "customized-dialog-title"
7305
7477
  }, React__default.createElement(Typography, {
@@ -8007,7 +8179,12 @@ function CreateNewQuestionDialog$1(_ref) {
8007
8179
  examSessionId = _ref.examSessionId;
8008
8180
  return React__default.createElement(material.Dialog, {
8009
8181
  onClose: toggleCreateQuestion,
8010
- open: openCreateQuestionDialog
8182
+ open: openCreateQuestionDialog,
8183
+ PaperProps: {
8184
+ sx: {
8185
+ minWidth: "363px"
8186
+ }
8187
+ }
8011
8188
  }, React__default.createElement(DialogTitle, {
8012
8189
  id: "customized-dialog-title"
8013
8190
  }, React__default.createElement(Typography, {