Skip to content

Commit

Permalink
feat(PollDraftHandler): browser drafts from conversation settings
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Dec 19, 2024
1 parent 2738009 commit e0ebf4e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
26 changes: 25 additions & 1 deletion src/components/ConversationSettings/LobbySettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,25 @@
:token="token"
container=".import-email-participants"
@close="isImportEmailsDialogOpen = false" />

<template v-if="canCreatePollDrafts">
<h4 class="app-settings-section__subtitle">
{{ t('spreed', 'Poll drafts') }}
</h4>
<NcButton @click="openPollDraftHandler">
<template #icon>
<IconPoll :size="20" />
</template>
{{ t('spreed', 'Browse poll drafts') }}
</NcButton>
</template>
</div>
</div>
</template>

<script>
import IconFileUpload from 'vue-material-design-icons/FileUpload.vue'
import IconPoll from 'vue-material-design-icons/Poll.vue'

import { showError, showSuccess } from '@nextcloud/dialogs'
import { t } from '@nextcloud/l10n'
Expand All @@ -81,8 +94,9 @@ import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'

import ImportEmailsDialog from '../ImportEmailsDialog.vue'

import { WEBINAR } from '../../constants.js'
import { CONVERSATION, WEBINAR } from '../../constants.js'
import { hasTalkFeature } from '../../services/CapabilitiesManager.ts'
import { EventBus } from '../../services/EventBus.ts'
import { futureRelativeTime } from '../../utils/formattedTime.ts'

const ONE_DAY_IN_MS = 24 * 60 * 60 * 1000
Expand All @@ -92,6 +106,7 @@ export default {

components: {
IconFileUpload,
IconPoll,
ImportEmailsDialog,
NcButton,
NcCheckboxRadioSwitch,
Expand Down Expand Up @@ -182,6 +197,11 @@ export default {
getRelativeTime() {
return futureRelativeTime(this.lobbyTimer)
},

canCreatePollDrafts() {
return hasTalkFeature(this.token, 'talk-polls-drafts') && this.$store.getters.isModerator
&& [CONVERSATION.TYPE.GROUP, CONVERSATION.TYPE.PUBLIC].includes(this.conversation.type)
},
},

methods: {
Expand Down Expand Up @@ -227,6 +247,10 @@ export default {

this.isLobbyTimerLoading = false
},

openPollDraftHandler() {
EventBus.emit('poll-drafts-open', { selector: '#settings-section_meeting'})
}
},
}
</script>
Expand Down
4 changes: 3 additions & 1 deletion src/components/PollViewer/PollDraftHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<template>
<NcDialog class="drafts"
:name="t('spreed', 'Poll drafts')"
:container="container"
size="normal"
close-on-click-outside
v-on="$listeners"
Expand Down Expand Up @@ -54,6 +55,7 @@ import { usePollsStore } from '../../stores/polls.ts'

const props = defineProps<{
token: string,
container?: string,
editorOpened?: boolean,
}>()
const emit = defineEmits<{
Expand All @@ -73,7 +75,7 @@ const pollDrafts = computed(() => pollsStore.getDrafts(props.token))
* @param id poll draft ID
*/
function openPollEditor(id: number|null) {
EventBus.emit('poll-editor-open', { id, fromDrafts: !props.editorOpened })
EventBus.emit('poll-editor-open', { id, fromDrafts: !props.editorOpened, selector: props.container })
}
</script>

Expand Down
4 changes: 3 additions & 1 deletion src/components/PollViewer/PollEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<template>
<NcDialog :name="t('spreed', 'Create new poll')"
:close-on-click-outside="!isFilled"
:container="container"
v-on="$listeners"
@update:open="emit('close')">
<NcButton v-if="supportPollDrafts && isOpenedFromDraft"
Expand Down Expand Up @@ -140,6 +141,7 @@ import { validatePollForm } from '../../utils/validatePollForm.ts'

const props = defineProps<{
token: string,
container?: string,
}>()
const emit = defineEmits<{
(event: 'close'): void,
Expand Down Expand Up @@ -290,7 +292,7 @@ async function createPollDraft() {
* Open a PollDraftHandler dialog
*/
function openPollDraftHandler() {
EventBus.emit('poll-drafts-open')
EventBus.emit('poll-drafts-open', {})
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/components/PollViewer/PollManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const pollEditorRef = ref(null)

const showPollEditor = ref(false)
const showPollDraftHandler = ref(false)
const container = ref<string|undefined>(undefined)

const token = computed(() => store.getters.getConversationSettingsToken() || store.getters.getToken())
const canCreatePollDrafts = computed(() => {
Expand All @@ -35,11 +36,13 @@ onBeforeUnmount(() => {
EventBus.off('poll-drafts-open', openPollDraftHandler)
})

const openPollDraftHandler = () => {
const openPollDraftHandler = ({ selector }: { selector?: string }) => {
container.value = selector
showPollDraftHandler.value = true
}

const openPollEditor = ({ id, fromDrafts }: { id: number|null, fromDrafts: boolean }) => {
const openPollEditor = ({ id, fromDrafts, selector }: { id: number|null, fromDrafts: boolean, selector?: string }) => {
container.value = selector
showPollEditor.value = true
nextTick(() => {
pollEditorRef.value?.fillPollEditorFromDraft(id, fromDrafts)
Expand All @@ -56,10 +59,12 @@ const openPollEditor = ({ id, fromDrafts }: { id: number|null, fromDrafts: boole
<PollEditor v-if="showPollEditor"
ref="pollEditorRef"
:token="token"
:container="container"
@close="showPollEditor = false" />
<!-- Poll drafts dialog -->
<PollDraftHandler v-if="canCreatePollDrafts && showPollDraftHandler"
:token="token"
:container="container"
:editor-opened="showPollEditor"
@close="showPollDraftHandler = false" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/RightSidebar/SharedItems/SharedItemsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export default {
},

openPollDraftHandler() {
EventBus.emit('poll-drafts-open')
EventBus.emit('poll-drafts-open', {})
}
},
}
Expand Down

0 comments on commit e0ebf4e

Please sign in to comment.