From 62d1f55ebaac192c355eb8f7e70045b01a81405b Mon Sep 17 00:00:00 2001 From: "jue.hou" Date: Thu, 17 Oct 2024 12:20:48 +0300 Subject: [PATCH 1/3] import stories --- client/components/GroupView/GroupFunctions.js | 14 ++++ .../components/GroupView/ImportStoryModal.js | 74 +++++++++++++++++++ client/util/redux/groupsReducer.js | 33 ++++++++- .../revita/en/LC_MESSAGES/messages.json | 10 ++- .../revita/fi/LC_MESSAGES/messages.json | 10 ++- .../revita/it/LC_MESSAGES/messages.json | 10 ++- .../revita/ru/LC_MESSAGES/messages.json | 10 ++- .../revita/zh/LC_MESSAGES/messages.json | 10 ++- 8 files changed, 160 insertions(+), 11 deletions(-) create mode 100644 client/components/GroupView/ImportStoryModal.js diff --git a/client/components/GroupView/GroupFunctions.js b/client/components/GroupView/GroupFunctions.js index 7a309602..4ac1f9fc 100644 --- a/client/components/GroupView/GroupFunctions.js +++ b/client/components/GroupView/GroupFunctions.js @@ -10,6 +10,7 @@ import { getTestQuestions } from 'Utilities/redux/testReducer' import { Button } from 'react-bootstrap' import useWindowDimensions from 'Utilities/windowDimensions' import GroupLearningSettingsModal from './GroupLearningSettingsModal' +import ImportStoryModal from './ImportStoryModal' const GroupFunctions = ({ group, @@ -29,6 +30,7 @@ const GroupFunctions = ({ } = group const teacherView = useSelector(({ user }) => user.data.user.is_teacher) const [learningModalGroupId, setLearningModalGroupId] = useState(null) + const [importStoryModalOpen, setImportStoryModalOpen] = useState(false) const { width } = useWindowDimensions() const testEnabled = currTestDeadline - Date.now() > 0 const testButtonVariant = testEnabled ? 'danger' : 'primary' @@ -89,6 +91,9 @@ const GroupFunctions = ({ dispatch(getTestQuestions(language, groupId, true)) } + + + return ( <> {width >= 640 ? ( @@ -114,6 +119,9 @@ const GroupFunctions = ({ groupId={learningModalGroupId} /> )} + {isTeaching && teacherView && ( + + )} {isTeaching && teacherView && ( )} + {isTeaching && teacherView && ( + + + )} ) : ( diff --git a/client/components/GroupView/ImportStoryModal.js b/client/components/GroupView/ImportStoryModal.js new file mode 100644 index 00000000..b895b997 --- /dev/null +++ b/client/components/GroupView/ImportStoryModal.js @@ -0,0 +1,74 @@ +import React, { useState } from 'react' +import { useSelector, useDispatch } from 'react-redux' +import { Modal, Dropdown, Input } from 'semantic-ui-react' +import { FormattedMessage, FormattedHTMLMessage, useIntl } from 'react-intl' +import { Button } from 'react-bootstrap' +import { importStoriesFromGroup } from 'Utilities/redux/groupsReducer' +import { getAllStories } from 'Utilities/redux/storiesReducer' + +const ImportStoryModal = ({ open, setOpen, groupId }) => { + const dispatch = useDispatch() + const intl = useIntl() + const { groups, pending, storyImported } = useSelector(({ groups }) => groups) + const [selectedGroups, setSelectedGroups] = useState([]) + const [message, setMessage] = useState('') + const group = groups.find(group => group.group_id === groupId) + const { groupName } = group + + const options = groups.map(group => ({key: group.group_id, text: group.groupName, value: group.group_id})) + const submitGroupImport = async () => { + // console.log(selectedGroups) + // console.log(message) + await dispatch(importStoriesFromGroup(groupId, selectedGroups, message)) + dispatch( + getAllStories(learningLanguage, { + sort_by: 'date', + order: -1, + }) + ) + setOpen(false) + setSelectedGroups([]) + setMessage('') + } + + return ( + setOpen(false)} onOpen={() => setOpen(true)} open={open}> + + : {groupName} + + +

+ +

+ + setSelectedGroups(value)} + style={{ marginTop: '1em' }} + /> + + + setMessage(e.target.value)} /> + +
+ + + + +
+ ) +} + +export default ImportStoryModal \ No newline at end of file diff --git a/client/util/redux/groupsReducer.js b/client/util/redux/groupsReducer.js index 501f9a41..0186d88e 100644 --- a/client/util/redux/groupsReducer.js +++ b/client/util/redux/groupsReducer.js @@ -123,11 +123,18 @@ export const confirmGroupInvitation = token => { return callBuilder(route, prefix, 'post', payload) } +export const importStoriesFromGroup = (groupId, selectedGroups, message) => { + const route = `/groups/${groupId}/import` + const prefix = 'IMPORT_STORIES' + const payload = { src_group_ids: selectedGroups, message } + return callBuilder(route, prefix, 'post', payload) +} + export const emptyLastAddInfo = () => ({ type: 'EMPTY_LAST_ADD_INFO', }) -export default (state = { groups: [], joinPending: false, deleteSuccessful: false }, action) => { +export default (state = { groups: [], joinPending: false, deleteSuccessful: false, storyImported: -1 }, action) => { switch (action.type) { case 'GET_GROUPS_ATTEMPT': return { @@ -408,6 +415,30 @@ export default (state = { groups: [], joinPending: false, deleteSuccessful: fals ...state, pending: false, } + + case 'IMPORT_STORIES_ATTEMPT': + return { + ...state, + pending: true, + } + case 'IMPORT_STORIES_FAILURE': + return { + ...state, + pending: false, + } + case 'IMPORT_STORIES_SUCCESS': + return { + ...state, + storyImported: action.response.num_story_imported, + pending: false, + } + + case 'CLEAN_STORY_IMPORT': + return { + ...state, + storyImported: -1, + } + default: return state } diff --git a/client/util/translations/revita/en/LC_MESSAGES/messages.json b/client/util/translations/revita/en/LC_MESSAGES/messages.json index 8fefe4de..439dc02a 100755 --- a/client/util/translations/revita/en/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/en/LC_MESSAGES/messages.json @@ -1677,7 +1677,13 @@ "group-hidden-story": "Thе story is hidden for this group", "flashcard-translation-target-language": "Translation target language:", "flashcard-upload-instructions-2": "Note (for now): the words will be translated only into the language you select above. If you want them to work with another language, please upload another deck of cards in another file.", - "release-story": "Release story", + "release-story": "Unhide story", "hide-story": "Hide story", - "share-as-a-hidden-story": "Share as a hidden story" + "share-as-a-hidden-story": "Share as hidden", + "import-story": "Import story", + "import-story-label": "Import stories from other groups", + "import-story-description": "
Select groups to import
", + "import-from": "Import stories from ...", + "import-story-message": "Message:", + "correct-answer-to-question": "Correct!" } \ No newline at end of file diff --git a/client/util/translations/revita/fi/LC_MESSAGES/messages.json b/client/util/translations/revita/fi/LC_MESSAGES/messages.json index 38ea5988..f6b3eceb 100755 --- a/client/util/translations/revita/fi/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/fi/LC_MESSAGES/messages.json @@ -1676,7 +1676,13 @@ "group-hidden-story": "Tarina on piilotettu tältä ryhmältä", "flashcard-translation-target-language": "Käännöksen kieli:", "flashcard-upload-instructions-2": "Huomautus (toistaiseksi): nämä kortit käännetään vain yllä valitsemaksesi kieleksi. Jos haluat niiden toimivan toisella kielellä, lataa toinen korttipakka toisessa tiedostossa.", - "release-story": "Release story", + "release-story": "Unhide story", "hide-story": "Hide story", - "share-as-a-hidden-story": "Share as a hidden story" + "share-as-a-hidden-story": "Share as hidden", + "import-story": "Import story", + "import-story-label": "Import stories from other groups", + "import-story-description": "
Select groups to import
", + "import-from": "Import stories from ...", + "import-story-message": "Message:", + "correct-answer-to-question": "Oikein!" } \ No newline at end of file diff --git a/client/util/translations/revita/it/LC_MESSAGES/messages.json b/client/util/translations/revita/it/LC_MESSAGES/messages.json index cda52ca9..aa39185c 100755 --- a/client/util/translations/revita/it/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/it/LC_MESSAGES/messages.json @@ -1675,7 +1675,13 @@ "group-hidden-story": "La storia è nascosta per questo gruppo", "flashcard-translation-target-language": "Lingua di traduzione:", "flashcard-upload-instructions-2": "Nota (per ora): le parole saranno tradotte solo nella lingua selezionata sopra. Se vuoi che funzionino con un'altra lingua, carica un altro mazzo di carte in un altro file.", - "release-story": "Release story", + "release-story": "Unhide story", "hide-story": "Hide story", - "share-as-a-hidden-story": "Share as a hidden story" + "share-as-a-hidden-story": "Share as hidden", + "import-story": "Import story", + "import-story-label": "Import stories from other groups", + "import-story-description": "
Select groups to import
", + "import-from": "Import stories from ...", + "import-story-message": "Message:", + "correct-answer-to-question": "Correct!" } \ No newline at end of file diff --git a/client/util/translations/revita/ru/LC_MESSAGES/messages.json b/client/util/translations/revita/ru/LC_MESSAGES/messages.json index d717a3d1..8bc8c759 100755 --- a/client/util/translations/revita/ru/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/ru/LC_MESSAGES/messages.json @@ -1678,7 +1678,13 @@ "group-hidden-story": "История скрыта для этой группы", "flashcard-translation-target-language": "Язык перевода:", "flashcard-upload-instructions-2": "Примечание (на данный момент): слова будут переведены только на язык выбранный выше. Чтобы они работали с другим языком, загрузи другую колоду карт в другом файле.", - "release-story": "Release story", + "release-story": "Unhide story", "hide-story": "Hide story", - "share-as-a-hidden-story": "Share as a hidden story" + "share-as-a-hidden-story": "Share as hidden", + "import-story": "Import story", + "import-story-label": "Import stories from other groups", + "import-story-description": "
Select groups to import
", + "import-from": "Import stories from ...", + "import-story-message": "Message:", + "correct-answer-to-question": "Correct!" } \ No newline at end of file diff --git a/client/util/translations/revita/zh/LC_MESSAGES/messages.json b/client/util/translations/revita/zh/LC_MESSAGES/messages.json index 1eebdac4..16f3fb6d 100644 --- a/client/util/translations/revita/zh/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/zh/LC_MESSAGES/messages.json @@ -1050,7 +1050,13 @@ "group-hidden-story": "本文在当前小组内处于隐藏状态", "flashcard-translation-target-language": "翻译目标语言:", "flashcard-upload-instructions-2": "Note (for now): the words will be translated only into the language you select above. If you want them to work with another language, please upload another deck of cards in another file.", - "release-story": "Release story", + "release-story": "Unhide story", "hide-story": "Hide story", - "share-as-a-hidden-story": "Share as a hidden story" + "share-as-a-hidden-story": "Share as hidden", + "import-story": "Import story", + "import-story-label": "Import stories from other groups", + "import-story-description": "
Select groups to import
", + "import-from": "Import stories from ...", + "import-story-message": "Message:", + "correct-answer-to-question": "Correct!" } \ No newline at end of file From 9c71cfec625f0b5f87ff05374ffaf49c600f12e7 Mon Sep 17 00:00:00 2001 From: "jue.hou" Date: Thu, 17 Oct 2024 12:54:44 +0300 Subject: [PATCH 2/3] minor fix --- client/components/GroupView/ImportStoryModal.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/components/GroupView/ImportStoryModal.js b/client/components/GroupView/ImportStoryModal.js index b895b997..a51d92de 100644 --- a/client/components/GroupView/ImportStoryModal.js +++ b/client/components/GroupView/ImportStoryModal.js @@ -15,7 +15,8 @@ const ImportStoryModal = ({ open, setOpen, groupId }) => { const group = groups.find(group => group.group_id === groupId) const { groupName } = group - const options = groups.map(group => ({key: group.group_id, text: group.groupName, value: group.group_id})) + const options = groups.filter(group => group.group_id !== groupId).map( + group => ({key: group.group_id, text: group.groupName, value: group.group_id})) const submitGroupImport = async () => { // console.log(selectedGroups) // console.log(message) From cdfd18cc6c5b878e0a5f30062f50cf7261fd4d27 Mon Sep 17 00:00:00 2001 From: "jue.hou" Date: Thu, 17 Oct 2024 12:56:43 +0300 Subject: [PATCH 3/3] minor fix --- client/components/GroupView/ImportStoryModal.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client/components/GroupView/ImportStoryModal.js b/client/components/GroupView/ImportStoryModal.js index a51d92de..8a999c7c 100644 --- a/client/components/GroupView/ImportStoryModal.js +++ b/client/components/GroupView/ImportStoryModal.js @@ -13,7 +13,6 @@ const ImportStoryModal = ({ open, setOpen, groupId }) => { const [selectedGroups, setSelectedGroups] = useState([]) const [message, setMessage] = useState('') const group = groups.find(group => group.group_id === groupId) - const { groupName } = group const options = groups.filter(group => group.group_id !== groupId).map( group => ({key: group.group_id, text: group.groupName, value: group.group_id})) @@ -22,7 +21,7 @@ const ImportStoryModal = ({ open, setOpen, groupId }) => { // console.log(message) await dispatch(importStoriesFromGroup(groupId, selectedGroups, message)) dispatch( - getAllStories(learningLanguage, { + getAllStories(group.language, { sort_by: 'date', order: -1, }) @@ -35,7 +34,7 @@ const ImportStoryModal = ({ open, setOpen, groupId }) => { return ( setOpen(false)} onOpen={() => setOpen(true)} open={open}> - : {groupName} + : {group.groupName}