-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
feat: configure toast timeout #62689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kristian-zendato
wants to merge
1
commit into
master
Choose a base branch
from
feat/toast-timeout-configuration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,14 @@ | |
| namespace OCA\Theming\Listener; | ||
|
|
||
| use OCA\Theming\AppInfo\Application; | ||
| use OCA\Theming\ConfigLexicon; | ||
| use OCA\Theming\Service\JSDataService; | ||
| use OCA\Theming\Service\ThemeInjectionService; | ||
| use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent; | ||
| use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; | ||
| use OCP\AppFramework\Http\TemplateResponse; | ||
| use OCP\AppFramework\Services\IInitialState; | ||
| use OCP\Config\IUserConfig; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
| use OCP\IConfig; | ||
|
|
@@ -32,6 +34,7 @@ public function __construct( | |
| private ThemeInjectionService $themeInjectionService, | ||
| private IUserSession $userSession, | ||
| private IConfig $config, | ||
| private IUserConfig $userConfig, | ||
| ) { | ||
| } | ||
|
|
||
|
|
@@ -51,6 +54,17 @@ public function handle(Event $event): void { | |
| } | ||
| return false; | ||
| }); | ||
|
|
||
| $this->initialState->provideLazyInitialState('toastTimeout', function (): int { | ||
| if ($this->userSession->getUser()) { | ||
| $uid = $this->userSession->getUser()->getUID(); | ||
| $value = $this->userConfig->getValueInt($uid, Application::APP_ID, ConfigLexicon::TOAST_TIMEOUT, ConfigLexicon::TOAST_TIMEOUT_DEFAULT); | ||
| if (in_array($value, BeforePreferenceListener::TOAST_TIMEOUT_VALUES, true) || $value === ConfigLexicon::TOAST_TIMEOUT_DEFAULT) { | ||
| return $value; | ||
| } | ||
| } | ||
| return ConfigLexicon::TOAST_TIMEOUT_DEFAULT; | ||
| }); | ||
|
Comment on lines
+58
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is better to exposed as a capability instead - because this might also be used by clients. |
||
| } | ||
|
|
||
| $this->themeInjectionService->injectHeaders(); | ||
|
|
||
110 changes: 110 additions & 0 deletions
110
apps/theming/src/components/UserSectionToastTimeout.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| <!-- | ||
| - SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| - SPDX-License-Identifier: AGPL-3.0-or-later | ||
| --> | ||
|
|
||
| <script setup lang="ts"> | ||
| import axios from '@nextcloud/axios' | ||
| import { | ||
| setToastTimeout, | ||
| showError, | ||
| TOAST_DEFAULT_TIMEOUT, | ||
| TOAST_PERMANENT_TIMEOUT, | ||
| } from '@nextcloud/dialogs' | ||
| import { loadState } from '@nextcloud/initial-state' | ||
| import { t } from '@nextcloud/l10n' | ||
| import { generateOcsUrl } from '@nextcloud/router' | ||
| import { computed, ref } from 'vue' | ||
| import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch' | ||
| import NcSettingsSection from '@nextcloud/vue/components/NcSettingsSection' | ||
| import { logger } from '../utils/logger.ts' | ||
|
|
||
| const TOAST_TIMEOUT_15S = 15_000 | ||
| const TOAST_TIMEOUT_30S = 30_000 | ||
|
|
||
| const toastTimeout = ref(loadState<number>('theming', 'toastTimeout', TOAST_DEFAULT_TIMEOUT)) | ||
|
|
||
| const options = computed(() => [ | ||
| { | ||
| value: TOAST_DEFAULT_TIMEOUT, | ||
| label: t('theming', 'Default ({time} seconds)', { time: TOAST_DEFAULT_TIMEOUT / 1000 }), | ||
| }, | ||
| { | ||
| value: TOAST_TIMEOUT_15S, | ||
| label: t('theming', '15 seconds'), | ||
| }, | ||
| { | ||
| value: TOAST_TIMEOUT_30S, | ||
| label: t('theming', '30 seconds'), | ||
| }, | ||
| { | ||
| value: TOAST_PERMANENT_TIMEOUT, | ||
| label: t('theming', 'Never dismiss'), | ||
| }, | ||
| ]) | ||
|
|
||
| /** | ||
| * Persist and apply the selected toast timeout | ||
| * | ||
| * @param value - Selected timeout preference value | ||
| */ | ||
| async function updateToastTimeout(value: string | number | boolean) { | ||
| const nextValue = Number(value) | ||
| const previous = toastTimeout.value | ||
| toastTimeout.value = nextValue | ||
| setToastTimeout(nextValue) | ||
|
|
||
| const url = generateOcsUrl('apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', { | ||
| appId: 'theming', | ||
| configKey: 'toast_timeout', | ||
| }) | ||
|
|
||
| try { | ||
| if (nextValue === TOAST_DEFAULT_TIMEOUT) { | ||
| await axios.delete(url) | ||
| } else { | ||
| await axios.post(url, { | ||
| configValue: String(nextValue), | ||
| }) | ||
| } | ||
| } catch (error) { | ||
| toastTimeout.value = previous | ||
| setToastTimeout(previous) | ||
| logger.error('Could not update toast timeout', { error }) | ||
| showError(t('theming', 'Could not update toast timeout')) | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <NcSettingsSection | ||
| :name="t('theming', 'Toast notifications')" | ||
| :description="t('theming', 'Set how long toast messages stay visible. Choose a longer duration if you need more time to read them.')"> | ||
| <fieldset class="toast-timeout"> | ||
| <legend class="hidden-visually"> | ||
| {{ t('theming', 'Toast timeout') }} | ||
| </legend> | ||
| <NcCheckboxRadioSwitch | ||
| v-for="option in options" | ||
| :key="option.value" | ||
| :modelValue="toastTimeout" | ||
| type="radio" | ||
| name="toast_timeout" | ||
| :value="option.value" | ||
| @update:modelValue="updateToastTimeout"> | ||
| {{ option.label }} | ||
| </NcCheckboxRadioSwitch> | ||
| </fieldset> | ||
| </NcSettingsSection> | ||
| </template> | ||
|
|
||
| <style scoped lang="scss"> | ||
| .toast-timeout { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 4px; | ||
| border: 0; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to specify the default as this is handled by the config lexicon