Skip to content

Commit

Permalink
group sharing a hidden story
Browse files Browse the repository at this point in the history
  • Loading branch information
hj940709 committed Oct 14, 2024
1 parent 7f6067b commit 5249254
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 9 deletions.
21 changes: 20 additions & 1 deletion client/components/LibraryView/StoryListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -22,6 +27,7 @@ const StoryTitle = ({
setConfirmationOpen,
storyGroupShareInfo,
handleControlledStoryCancel,
setSharedStoryVisibility,
}) => {
const learningLanguage = useSelector(learningLanguageSelector)
const {user, teacherView} = useSelector(({ user }) => user.data)
Expand Down Expand Up @@ -71,6 +77,8 @@ const StoryTitle = ({
isTeacher={teacherView}
currentGroup={currentGroup}
handleControlledStoryCancel={handleControlledStoryCancel}
hidden={storyGroupShareInfo.hidden}
setSharedStoryVisibility={setSharedStoryVisibility}
/>
)
}
Expand Down Expand Up @@ -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
Expand All @@ -382,6 +400,7 @@ const StoryListItem = ({ story, libraryShown, selectedGroup }) => {
libraryShown={libraryShown}
storyGroupShareInfo={storyGroupShareInfo}
handleControlledStoryCancel={handleControlledStoryCancel}
setSharedStoryVisibility={setSharedStoryVisibility}
/>
</Card.Content>
<Card.Content extra className="story-card-actions-cont">
Expand Down
12 changes: 10 additions & 2 deletions client/components/StoryView/ShareStory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -106,6 +108,12 @@ const ShareStory = ({ story, isOpen, setOpen }) => {
</option>
))}
</select>
<Checkbox
label={intl.formatMessage({ id: 'share-as-a-hidden-story' })}
checked={isHiddenStory}
onChange={() => setIsHiddenStory(!isHiddenStory)}
style={{ marginLeft: '2rem' }}
/>
</div>
<span className="sm-label" style={{ marginTop: '5em' }}>
<FormattedMessage id="write-a-message-for-the-receiver-optional" />
Expand Down
7 changes: 7 additions & 0 deletions client/components/StoryView/StoryDetailsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const StoryDetailsModal = ({
isTeacher,
currentGroup,
handleControlledStoryCancel,
hidden,
setSharedStoryVisibility,
}) => {
const {
title,
Expand Down Expand Up @@ -179,6 +181,11 @@ const StoryDetailsModal = ({
variant="secondary"
translationId="Share"
/>
<CustomButton
onClick={() => setSharedStoryVisibility(story._id, hidden === true)}
variant="secondary"
translationId={hidden && "release-story" || "hide-story"}
/>
</div>
<div>
<CustomButton
Expand Down
3 changes: 2 additions & 1 deletion client/util/redux/shareReducer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import callBuilder from '../apiConnection'

export const shareStory = (storyId, groups, users, message) => {
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)
Expand Down
32 changes: 32 additions & 0 deletions client/util/redux/storiesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion client/util/translations/revita/en/LC_MESSAGES/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
5 changes: 4 additions & 1 deletion client/util/translations/revita/fi/LC_MESSAGES/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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<ul><li>Sallitut tiedostomuodot ovat .TXT ja .DOCX (.DOC ei ole tuettu)</li>\n<li>Ensimmäisellä rivillä on oltava tarinan <b>otsikko</b></li>\n</ul>"
"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"
}
5 changes: 4 additions & 1 deletion client/util/translations/revita/it/LC_MESSAGES/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:<ul><li>Seleziona un file con estensione .TXT o .DOCX (altre estensioni non supportate).</li><li>La prima riga deve contenere il <b>titolo</b> della storia.</li></ul>"
"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"
}
5 changes: 4 additions & 1 deletion client/util/translations/revita/ru/LC_MESSAGES/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1677,5 +1677,8 @@
"flashcard-btn-explanation": "Практиковаться с карточками из этой истории!",
"group-hidden-story": "История скрыта для этой группы",
"flashcard-translation-target-language": "Язык перевода:",
"old": "Пожалуйста, выбери файл, в котором содержится текст:<ul><li>У файла должно быть расширение .TXT или .DOCX</li><li>На первой строке обязательно должен быть только <b>заголовок</b> — название текста</li></ul>"
"flashcard-upload-instructions-2": "Примечание (на данный момент): слова будут переведены только на язык выбранный выше. Чтобы они работали с другим языком, загрузи другую колоду карт в другом файле.",
"release-story": "Release story",
"hide-story": "Hide story",
"share-as-a-hidden-story": "Share as a hidden story"
}
5 changes: 4 additions & 1 deletion client/util/translations/revita/zh/LC_MESSAGES/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 5249254

Please sign in to comment.