forked from ashkanm04/it-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(encryption): alert on decryption error (CorentinTh#711)
* update(c-alert): Add variant 'error' * fix(encryption): Alert decryption error (CorentinTh#652) * feat(c-alert): added title * refactor(composable): mutualized computedCatch --------- Co-authored-by: code2933 <[email protected]>
- Loading branch information
1 parent
4d5a67d
commit 02b0d0d
Showing
5 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,22 @@ | ||
import { type Ref, ref, watchEffect } from 'vue'; | ||
|
||
export { computedCatch }; | ||
|
||
function computedCatch<T, D>(getter: () => T, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref<T | D>, Ref<string | undefined>]; | ||
function computedCatch<T, D>(getter: () => T, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) { | ||
const error = ref<string | undefined>(); | ||
const value = ref<T | D | undefined>(); | ||
|
||
watchEffect(() => { | ||
try { | ||
error.value = undefined; | ||
value.value = getter(); | ||
} | ||
catch (err) { | ||
error.value = err instanceof Error ? err.message : err?.toString() ?? defaultErrorMessage; | ||
value.value = defaultValue; | ||
} | ||
}); | ||
|
||
return [value, error] as const; | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
<script lang="ts" setup> | ||
const variants = ['warning'] as const; | ||
const variants = ['warning', 'error'] as const; | ||
</script> | ||
|
||
<template> | ||
<h2>Basic</h2> | ||
<c-alert v-for="variant in variants" :key="variant" :type="variant" mb-4> | ||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni reprehenderit itaque enim? Suscipit magni optio velit | ||
quia, eveniet repellat pariatur quaerat laudantium dignissimos natus, beatae deleniti adipisci, atque necessitatibus | ||
odio! | ||
</c-alert> | ||
|
||
<h2>With title</h2> | ||
<c-alert v-for="variant in variants" :key="variant" :type="variant" title="This is the title" mb-4> | ||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni reprehenderit itaque enim? Suscipit magni optio velit | ||
quia, eveniet repellat pariatur quaerat laudantium dignissimos natus, beatae deleniti adipisci, atque necessitatibus | ||
odio! | ||
</c-alert> | ||
</template> |
This file contains 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 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