Skip to content

Commit

Permalink
feat: check if task API available, processing TODO
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory Vodyanov <[email protected]>
  • Loading branch information
GVodyanov committed Dec 23, 2024
1 parent e38362d commit 20b2554
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/components/MenuEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</template>
{{ t('mail', 'Unsnooze') }}
</ActionButton>
<ActionButton v-if="isTranslationAvailable"
<ActionButton v-if="isTranslationEnabled ?? false"
:close-after-click="true"
@click.prevent="$emit('open-translation-modal')">
<template #icon>
Expand Down Expand Up @@ -328,6 +328,7 @@ export default {
computed: {
...mapGetters([
'isSnoozeDisabled',
'isTranslationEnabled',
]),
account() {
const accountId = this.envelope.accountId ?? this.mailbox.accountId
Expand Down
8 changes: 0 additions & 8 deletions src/components/ThreadEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@
:with-select="false"
:with-show-source="true"
:more-actions-open.sync="moreActionsOpen"
:is-translation-available="!!availableTranslationLanguages.length"
@reply="onReply"
@delete="$emit('delete',envelope.databaseId)"
@show-source-modal="onShowSourceModal"
Expand Down Expand Up @@ -222,7 +221,6 @@
<TranslationModal v-if="showTranslationModal"
:rich-parameters="{}"
:message="plainTextBody"
:available-languages="availableTranslationLanguages"
@close="onCloseTranslationModal" />
</template>
</div>
Expand Down Expand Up @@ -317,7 +315,6 @@ import moment from '@nextcloud/moment'
import { translateTagDisplayName } from '../util/tag.js'
import { FOLLOW_UP_TAG_LABEL } from '../store/constants.js'
import { Text, toPlain } from '../util/text.js'
import { getTranslationLanguages } from '../service/translationService.js'

// Ternary loading state
const LOADING_DONE = 0
Expand Down Expand Up @@ -415,7 +412,6 @@ export default {
rawMessage: '', // Will hold the raw source of the message when requested
isInternal: true,
enabledSmartReply: loadState('mail', 'llm_freeprompt_available', false),
availableTranslationLanguages: [],
}
},
computed: {
Expand Down Expand Up @@ -618,10 +614,6 @@ export default {
clearInterval(this.$checkInterval)
}
}, 100)

const response = await getTranslationLanguages()
this.availableTranslationLanguages = response.data.ocs.data.languages
console.log('availableTranslationLanguages', this.availableTranslationLanguages)
},
beforeDestroy() {
if (this.seenTimer !== undefined) {
Expand Down
9 changes: 5 additions & 4 deletions src/components/TranslationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { showError, showSuccess } from '@nextcloud/dialogs'
import { NcButton, NcDialog, NcLoadingIcon, NcRichText, NcSelect } from '@nextcloud/vue'

import { translateText } from '../service/translationService.js'
import { mapGetters } from 'vuex'

export default {
name: 'TranslationModal',
Expand All @@ -99,10 +100,6 @@ export default {
type: Object,
required: true,
},
availableLanguages: {
type: Array,
required: true,
},
},

emits: ['close'],
Expand All @@ -118,6 +115,10 @@ export default {
},

computed: {
...mapGetters({
availableLanguages: 'getTranslationLanguages',
}),

userLanguage() {
return navigator.language.substring(0, 2)
},
Expand Down
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { fixAccountId } from './service/AccountService.js'
import { loadState } from '@nextcloud/initial-state'
import { createPinia, PiniaVuePlugin } from 'pinia'
import useOutboxStore from './store/outboxStore.js'
import { checkTranslationServiceAvailability } from './service/translationService.js'

Vue.use(PiniaVuePlugin)
const pinia = createPinia()
Expand Down Expand Up @@ -145,6 +146,8 @@ store.commit('setFollowUpFeatureAvailable', followUpFeatureAvailable)
const smimeCertificates = loadState('mail', 'smime-certificates', [])
store.commit('setSmimeCertificates', smimeCertificates)

checkTranslationServiceAvailability()

/* eslint-disable vue/match-component-file-name */
export default new Vue({
el: '#content',
Expand Down
35 changes: 32 additions & 3 deletions src/service/translationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,38 @@

import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import store from '../store/index.js'

const getTranslationLanguages = async function(options) {
return axios.get(generateOcsUrl('/translation/languages', undefined, options), options)
const checkTranslationServiceAvailability = function() {
/// TODO
// const response = await axios.post(generateOcsUrl('taskprocessing/tasktypes'), {
// appId: 'mail',

Check failure on line 13 in src/service/translationService.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected tab character
// })

const isAvailable = true
const languages = [
{
from: 'en',
fromLabel: 'English',
to: 'fr',
toLabel: 'French',
},
{
from: 'en',
fromLabel: 'English',
to: 'de',
toLabel: 'German',
},
{
from: 'fr',
fromLabel: 'French',
to: 'en',
toLabel: 'English',
},
]

store.commit('enableTranslation', isAvailable)
store.commit('setTranslationLanguages', languages)
}

const translateText = async function(text, fromLanguage, toLanguage) {
Expand Down Expand Up @@ -36,4 +65,4 @@ const translateText = async function(text, fromLanguage, toLanguage) {
}
}

export { getTranslationLanguages, translateText }
export { checkTranslationServiceAvailability, translateText }
2 changes: 2 additions & 0 deletions src/store/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,6 @@ export const getters = {
getInternalAddresses: (state) => state.internalAddress?.filter(internalAddress => internalAddress !== undefined),
hasCurrentUserPrincipalAndCollections: (state) => state.hasCurrentUserPrincipalAndCollections,
showSettingsForAccount: (state) => (accountId) => state.showAccountSettings === accountId,
isTranslationEnabled: (state) => state.isTranslationEnabled,
getTranslationLanguages: (state) => state.translationLanguages,
}
2 changes: 2 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export default new Store({
internalAddress: [],
hasCurrentUserPrincipalAndCollections: false,
showAccountSettings: null,
isTranslationEnabled: false,
translationLanguages: [],
},
getters,
mutations,
Expand Down
6 changes: 6 additions & 0 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,10 @@ export default {
showSettingsForAccount(state, accountId) {
state.showAccountSettings = accountId
},
enableTranslation(state, enabled) {
state.isTranslationEnabled = enabled
},
setTranslationLanguages(state, languages) {
state.translationLanguages = languages
},
}

0 comments on commit 20b2554

Please sign in to comment.