diff options
author | Rémy Raes <contact@remyraes.com> | 2023-04-10 14:25:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 14:25:32 +0200 |
commit | 6d58e6793d40df4fec518f37351868803a02a033 (patch) | |
tree | 8ba8b1fdf503579314e9475bee409e0ba549e7ad /src-vue/src/plugins/store.ts | |
parent | 0d4744ad1f05ea6410b4cbe4e1e0270e67055ce6 (diff) | |
download | FlightCore-6d58e6793d40df4fec518f37351868803a02a033.tar.gz FlightCore-6d58e6793d40df4fec518f37351868803a02a033.zip |
refactor: Notifications (#259)
* feat: wrap ElNotification class in a showNotification method
* refactor: replace notification invocations in mod views
* feat: add 'info' type to showNotification method
* refactor: replace notification invocations in repair view
* refactor: replace notification invocations in settings view
* refactor: replace notification invocations in developer view
* feat: showNotification method now returns a NotificationHandle
* feat: showNotification has a duration argument
* refactor: replace notification invocations in pull requests module
* refactor: replace notification invocation in repair view
* refactor: replace notification invocations in UI store
* refactor: remove unused import from play view
* refactor: use showErrorNotification method to wrap up error display
* fix: add missing showErrorNotification imports
* style: format code
* style: format ThunderstoreModCard.vue
* style: format pull_requests.ts
* style: format SettingsView.vue
* style: format RepairView.vue
* style: format DeveloperView.vue
* refactor: remove useless import
* refactor: add missing showErrorNotification invocation
* feat: showErrorNotification has an optional title argument
* style: format LocalModsView.vue
Diffstat (limited to 'src-vue/src/plugins/store.ts')
-rw-r--r-- | src-vue/src/plugins/store.ts | 86 |
1 files changed, 30 insertions, 56 deletions
diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index cdbd6738..6f878277 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -6,7 +6,7 @@ import { invoke } from "@tauri-apps/api"; import { GameInstall } from "../utils/GameInstall"; import { ReleaseCanal } from "../utils/ReleaseCanal"; import { FlightCoreVersion } from "../../../src-tauri/bindings/FlightCoreVersion"; -import { ElNotification, NotificationHandle } from 'element-plus'; +import { NotificationHandle } from 'element-plus'; import { NorthstarState } from '../utils/NorthstarState'; import { appDir } from '@tauri-apps/api/path'; import { open } from '@tauri-apps/api/dialog'; @@ -18,6 +18,7 @@ import { NorthstarMod } from "../../../src-tauri/bindings/NorthstarMod"; import { searchModule } from './modules/search'; import { i18n } from '../main'; import { pullRequestModule } from './modules/pull_requests'; +import { showErrorNotification, showNotification } from '../utils/ui'; const persistentStore = new Store('flight-core-settings.json'); @@ -128,12 +129,10 @@ export const store = createStore<FlightCoreStore>({ let is_valid_titanfall2_install = await invoke("verify_install_location", { gamePath: selected }) as boolean; if (is_valid_titanfall2_install) { state.game_path = selected; - ElNotification({ - title: i18n.global.tc('notification.game_folder.new.title'), - message: i18n.global.tc('notification.game_folder.new.text'), - type: 'success', - position: 'bottom-right' - }); + showNotification( + i18n.global.tc('notification.game_folder.new.title'), + i18n.global.tc('notification.game_folder.new.text') + ); try { notification_handle.close(); } @@ -156,12 +155,10 @@ export const store = createStore<FlightCoreStore>({ } else { // Not valid Titanfall2 install - ElNotification({ - title: i18n.global.tc('notification.game_folder.wrong.title'), - message: i18n.global.tc('notification.game_folder.wrong.text'), - type: 'error', - position: 'bottom-right' - }); + showErrorNotification( + i18n.global.tc('notification.game_folder.wrong.text'), + i18n.global.tc('notification.game_folder.wrong.title') + ); } } }, @@ -229,12 +226,7 @@ export const store = createStore<FlightCoreStore>({ }) .catch((error) => { console.error(error); - ElNotification({ - title: i18n.global.tc('generic.error'), - message: error, - type: 'error', - position: 'bottom-right' - }); + showErrorNotification(error); }); break; @@ -251,20 +243,11 @@ export const store = createStore<FlightCoreStore>({ await invoke("launch_northstar_steam_caller", { gameInstall: game_install, bypassChecks: no_checks }) .then((message) => { - ElNotification({ - title: 'Success', - type: 'success', - position: 'bottom-right' - }); + showNotification('Success'); }) .catch((error) => { console.error(error); - ElNotification({ - title: 'Error', - message: error, - type: 'error', - position: 'bottom-right' - }); + showErrorNotification(error); }); return; @@ -324,12 +307,7 @@ export const store = createStore<FlightCoreStore>({ }) .catch((error) => { console.error(error); - ElNotification({ - title: i18n.global.tc('generic.error'), - message: error, - type: 'error', - position: 'bottom-right' - }); + showErrorNotification(error); }); }, async toggleReleaseCandidate(state: FlightCoreStore) { @@ -346,12 +324,10 @@ export const store = createStore<FlightCoreStore>({ store.commit("checkNorthstarUpdates"); // Display notification to highlight change - ElNotification({ - title: i18n.global.tc(`channels.names.${state.northstar_release_canal}`), - message: i18n.global.tc('channels.release.switch.text', {canal: state.northstar_release_canal}), - type: 'success', - position: 'bottom-right' - }); + showNotification( + i18n.global.tc(`channels.names.${state.northstar_release_canal}`), + i18n.global.tc('channels.release.switch.text', {canal: state.northstar_release_canal}), + ); } } }); @@ -418,13 +394,12 @@ async function _initializeApp(state: any) { .catch((err) => { // Gamepath not found or other error console.error(err); - notification_handle = ElNotification({ - title: i18n.global.tc('notification.game_folder.not_found.title'), - message: i18n.global.tc('notification.game_folder.not_found.text'), - type: 'error', - position: 'bottom-right', - duration: 0 // Duration `0` means the notification will not auto-vanish - }); + notification_handle = showNotification( + i18n.global.tc('notification.game_folder.not_found.title'), + i18n.global.tc('notification.game_folder.not_found.text'), + 'error', + 0 // Duration `0` means the notification will not auto-vanish + ); }); } @@ -461,13 +436,12 @@ async function _checkForFlightCoreUpdates(state: FlightCoreStore) { if (flightcore_is_outdated) { let newest_flightcore_version = await invoke("get_newest_flightcore_version") as FlightCoreVersion; - ElNotification({ - title: i18n.global.tc('notification.flightcore_outdated.title'), - message: i18n.global.tc('notification.flightcore_outdated.text', {oldVersion: state.flightcore_version, newVersion: newest_flightcore_version.tag_name}), - type: 'warning', - position: 'bottom-right', - duration: 0 // Duration `0` means the notification will not auto-vanish - }); + showNotification( + i18n.global.tc('notification.flightcore_outdated.title'), + i18n.global.tc('notification.flightcore_outdated.text', {oldVersion: state.flightcore_version, newVersion: newest_flightcore_version.tag_name}), + 'warning', + 0 // Duration `0` means the notification will not auto-vanish + ); } } |