From 52492543fac4207b5379a2fa3a6ceab1077293fc Mon Sep 17 00:00:00 2001 From: "jue.hou" Date: Mon, 14 Oct 2024 15:28:10 +0300 Subject: [PATCH] group sharing a hidden story --- .../components/LibraryView/StoryListItem.js | 21 +++++++++++- client/components/StoryView/ShareStory.js | 12 +++++-- .../components/StoryView/StoryDetailsModal.js | 7 ++++ client/util/redux/shareReducer.js | 3 +- client/util/redux/storiesReducer.js | 32 +++++++++++++++++++ .../revita/en/LC_MESSAGES/messages.json | 5 ++- .../revita/fi/LC_MESSAGES/messages.json | 5 ++- .../revita/it/LC_MESSAGES/messages.json | 5 ++- .../revita/ru/LC_MESSAGES/messages.json | 5 ++- .../revita/zh/LC_MESSAGES/messages.json | 5 ++- 10 files changed, 91 insertions(+), 9 deletions(-) diff --git a/client/components/LibraryView/StoryListItem.js b/client/components/LibraryView/StoryListItem.js index 86e73f21c..ff1fd3dbf 100644 --- a/client/components/LibraryView/StoryListItem.js +++ b/client/components/LibraryView/StoryListItem.js @@ -4,7 +4,12 @@ import { Card, Dropdown, Button as SemanticButton, Icon, Popup } from 'semantic- import { Button } from 'react-bootstrap' import { Link } from 'react-router-dom' import { FormattedMessage } from 'react-intl' -import { removeStory, getAllStories, unshareStory as unshare } from 'Utilities/redux/storiesReducer' +import { + removeStory, + getAllStories, + unshareStory as unshare, + storyVisibilityChange +} from 'Utilities/redux/storiesReducer' import useWindowDimensions from 'Utilities/windowDimensions' import { getTextStyle, learningLanguageSelector } from 'Utilities/common' import ConfirmationWarning from 'Components/ConfirmationWarning' @@ -22,6 +27,7 @@ const StoryTitle = ({ setConfirmationOpen, storyGroupShareInfo, handleControlledStoryCancel, + setSharedStoryVisibility, }) => { const learningLanguage = useSelector(learningLanguageSelector) const {user, teacherView} = useSelector(({ user }) => user.data) @@ -71,6 +77,8 @@ const StoryTitle = ({ isTeacher={teacherView} currentGroup={currentGroup} handleControlledStoryCancel={handleControlledStoryCancel} + hidden={storyGroupShareInfo.hidden} + setSharedStoryVisibility={setSharedStoryVisibility} /> ) } @@ -366,6 +374,16 @@ const StoryListItem = ({ story, libraryShown, selectedGroup }) => { ) } + const setSharedStoryVisibility = async (storyId, visibility) => { + await dispatch(storyVisibilityChange(selectedGroup, storyId, visibility)) + dispatch( + getAllStories(learningLanguage, { + sort_by: 'date', + order: -1, + }) + ) + } + const storyGroupShareInfo = libraryShown.group ? story.groups.find(g => g?.group_id === currentGroup?.group_id) : null @@ -382,6 +400,7 @@ const StoryListItem = ({ story, libraryShown, selectedGroup }) => { libraryShown={libraryShown} storyGroupShareInfo={storyGroupShareInfo} handleControlledStoryCancel={handleControlledStoryCancel} + setSharedStoryVisibility={setSharedStoryVisibility} /> diff --git a/client/components/StoryView/ShareStory.js b/client/components/StoryView/ShareStory.js index e7ac966ac..ac7868a1c 100644 --- a/client/components/StoryView/ShareStory.js +++ b/client/components/StoryView/ShareStory.js @@ -3,6 +3,7 @@ import { Modal, Radio } from 'semantic-ui-react' import { FormattedMessage, useIntl } from 'react-intl' import { useDispatch, useSelector } from 'react-redux' import { Button, FormControl, Form } from 'react-bootstrap' +import { Checkbox } from 'semantic-ui-react' import { shareStory } from 'Utilities/redux/shareReducer' import { formatEmailList } from 'Utilities/common' @@ -17,6 +18,7 @@ const ShareStory = ({ story, isOpen, setOpen }) => { const [message, setMessage] = useState( intl.formatMessage({ id: 'share-story-with-group-default' }) ) + const [isHiddenStory, setIsHiddenStory] = useState(false) const EMAIL_MIN_LENGTH = 6 const ownEmail = useSelector(({ user }) => user.data.user.email) @@ -38,9 +40,9 @@ const ShareStory = ({ story, isOpen, setOpen }) => { setShowSelfAddWarning(true) } else { if (showOption === 'group') { - dispatch(shareStory(story._id, [shareTargetGroupId], [], message)) + dispatch(shareStory(story._id, [shareTargetGroupId], [], message, isHiddenStory)) } else { - dispatch(shareStory(story._id, [], formatEmailList(shareTargetUserEmails), message)) + dispatch(shareStory(story._id, [], formatEmailList(shareTargetUserEmails), message, false)) } setMessage('') setOpen(false) @@ -106,6 +108,12 @@ const ShareStory = ({ story, isOpen, setOpen }) => { ))} + setIsHiddenStory(!isHiddenStory)} + style={{ marginLeft: '2rem' }} + /> diff --git a/client/components/StoryView/StoryDetailsModal.js b/client/components/StoryView/StoryDetailsModal.js index 5155ced9c..42e35d0f3 100644 --- a/client/components/StoryView/StoryDetailsModal.js +++ b/client/components/StoryView/StoryDetailsModal.js @@ -19,6 +19,8 @@ const StoryDetailsModal = ({ isTeacher, currentGroup, handleControlledStoryCancel, + hidden, + setSharedStoryVisibility, }) => { const { title, @@ -179,6 +181,11 @@ const StoryDetailsModal = ({ variant="secondary" translationId="Share" /> + setSharedStoryVisibility(story._id, hidden === true)} + variant="secondary" + translationId={hidden && "release-story" || "hide-story"} + />
{ +export const shareStory = (storyId, groups, users, message, hidden_story) => { const route = `/stories/${storyId}/share` const payload = { share_groups: groups, share_users: users, share_message: message, + hidden_story, } const prefix = 'SHARE_STORY' return callBuilder(route, prefix, 'post', payload) diff --git a/client/util/redux/storiesReducer.js b/client/util/redux/storiesReducer.js index c90f0310f..0ffb3117f 100644 --- a/client/util/redux/storiesReducer.js +++ b/client/util/redux/storiesReducer.js @@ -91,6 +91,12 @@ export const unshareStory = (groupId, storyId) => { return callBuilder(route, prefix, 'post', {}) } +export const storyVisibilityChange = (groupId, storyId, visibility) => { + const route = `/groups/${groupId}/visibility` + const prefix = 'SET_STORY_VISIBILITY' + return callBuilder(route, prefix, 'post', {visibility, storyId}) +} + export const addEditStoryAnnotation = ( publicStory, publicNote, @@ -412,6 +418,32 @@ export default (state = initialState, action) => { draft.pending = false draft.error = false }) + + case 'SET_STORY_VISIBILITY_ATTEMPT': + return { + ...state, + pending: true, + error: false, + } + case 'SET_STORY_VISIBILITY_FAILURE': + return { + ...state, + pending: false, + error: true, + } + case 'SET_STORY_VISIBILITY_SUCCESS': + return produce(state, draft => { + const story = draft.data.find(story => story._id === action.response.story_id) + const changedGroup = story.groups.find(group => group.group_id === action.response.group_id) + story.groups = story.groups.map( + group => group.group_id !== action.response.group_id && group || {...changedGroup, hidden: action.response.hidden} + ) + draft.pending = false + draft.error = false + }) + + + 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 49be4f697..8fefe4de1 100755 --- a/client/util/translations/revita/en/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/en/LC_MESSAGES/messages.json @@ -1676,5 +1676,8 @@ "flashcard-btn-explanation": "Click to practice flashcards from this story!", "group-hidden-story": "Thе story is hidden for this group", "flashcard-translation-target-language": "Translation target language:", - "old": "" + "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", + "hide-story": "Hide story", + "share-as-a-hidden-story": "Share as a hidden story" } \ 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 ab26604b1..38ea59889 100755 --- a/client/util/translations/revita/fi/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/fi/LC_MESSAGES/messages.json @@ -1675,5 +1675,8 @@ "flashcard-btn-explanation": "Harjoittele tämän tarinan muistikortteja napsauttamalla tässä!", "group-hidden-story": "Tarina on piilotettu tältä ryhmältä", "flashcard-translation-target-language": "Käännöksen kieli:", - "old": "Valitse tiedosto, jonka sisällöllä haluat harjoitella\n
  • Sallitut tiedostomuodot ovat .TXT ja .DOCX (.DOC ei ole tuettu)
  • \n
  • Ensimmäisellä rivillä on oltava tarinan otsikko
  • \n
" + "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", + "hide-story": "Hide story", + "share-as-a-hidden-story": "Share as a hidden story" } \ 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 007cc8960..cda52ca94 100755 --- a/client/util/translations/revita/it/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/it/LC_MESSAGES/messages.json @@ -1674,5 +1674,8 @@ "flashcard-btn-explanation": "Clicca per esercitarti con le flashcard di questa storia!", "group-hidden-story": "La storia è nascosta per questo gruppo", "flashcard-translation-target-language": "Lingua di traduzione:", - "old": "Seleziona un file di testo contenente la storia:
  • Seleziona un file con estensione .TXT o .DOCX (altre estensioni non supportate).
  • La prima riga deve contenere il titolo della storia.
" + "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", + "hide-story": "Hide story", + "share-as-a-hidden-story": "Share as a hidden story" } \ 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 55e541293..d717a3d15 100755 --- a/client/util/translations/revita/ru/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/ru/LC_MESSAGES/messages.json @@ -1677,5 +1677,8 @@ "flashcard-btn-explanation": "Практиковаться с карточками из этой истории!", "group-hidden-story": "История скрыта для этой группы", "flashcard-translation-target-language": "Язык перевода:", - "old": "Пожалуйста, выбери файл, в котором содержится текст:
  • У файла должно быть расширение .TXT или .DOCX
  • На первой строке обязательно должен быть только заголовок — название текста
" + "flashcard-upload-instructions-2": "Примечание (на данный момент): слова будут переведены только на язык выбранный выше. Чтобы они работали с другим языком, загрузи другую колоду карт в другом файле.", + "release-story": "Release story", + "hide-story": "Hide story", + "share-as-a-hidden-story": "Share as a hidden story" } \ 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 d7bea5111..1eebdac4b 100644 --- a/client/util/translations/revita/zh/LC_MESSAGES/messages.json +++ b/client/util/translations/revita/zh/LC_MESSAGES/messages.json @@ -1049,5 +1049,8 @@ "flashcard-btn-explanation": "开始练习本文中的单词", "group-hidden-story": "本文在当前小组内处于隐藏状态", "flashcard-translation-target-language": "翻译目标语言:", - "old": "" + "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", + "hide-story": "Hide story", + "share-as-a-hidden-story": "Share as a hidden story" } \ No newline at end of file