mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-23 08:16:16 -04:00
refactor(token-generator): now using computedRefreshable
This commit is contained in:
parent
f6237376e1
commit
cf16cb195d
1 changed files with 7 additions and 10 deletions
|
@ -53,28 +53,25 @@
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useCopy } from '@/composable/copy';
|
import { useCopy } from '@/composable/copy';
|
||||||
import { ref, watch } from 'vue';
|
|
||||||
import { useQueryParam } from '@/composable/queryParams';
|
import { useQueryParam } from '@/composable/queryParams';
|
||||||
|
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||||
import { createToken } from './token-generator.service';
|
import { createToken } from './token-generator.service';
|
||||||
|
|
||||||
const token = ref('');
|
|
||||||
const length = useQueryParam({ name: 'length', defaultValue: 64 });
|
const length = useQueryParam({ name: 'length', defaultValue: 64 });
|
||||||
const { copy } = useCopy({ source: token, text: 'Token copied to the clipboard' });
|
|
||||||
|
|
||||||
const withUppercase = useQueryParam({ name: 'uppercase', defaultValue: true });
|
const withUppercase = useQueryParam({ name: 'uppercase', defaultValue: true });
|
||||||
const withLowercase = useQueryParam({ name: 'lowercase', defaultValue: true });
|
const withLowercase = useQueryParam({ name: 'lowercase', defaultValue: true });
|
||||||
const withNumbers = useQueryParam({ name: 'numbers', defaultValue: true });
|
const withNumbers = useQueryParam({ name: 'numbers', defaultValue: true });
|
||||||
const withSymbols = useQueryParam({ name: 'symbols', defaultValue: false });
|
const withSymbols = useQueryParam({ name: 'symbols', defaultValue: false });
|
||||||
|
|
||||||
watch([withUppercase, withLowercase, withNumbers, withSymbols, length], refreshToken, { immediate: true });
|
const [token, refreshToken] = computedRefreshable(() =>
|
||||||
|
createToken({
|
||||||
function refreshToken() {
|
|
||||||
token.value = createToken({
|
|
||||||
length: length.value,
|
length: length.value,
|
||||||
withUppercase: withUppercase.value,
|
withUppercase: withUppercase.value,
|
||||||
withLowercase: withLowercase.value,
|
withLowercase: withLowercase.value,
|
||||||
withNumbers: withNumbers.value,
|
withNumbers: withNumbers.value,
|
||||||
withSymbols: withSymbols.value,
|
withSymbols: withSymbols.value,
|
||||||
});
|
}),
|
||||||
}
|
);
|
||||||
|
|
||||||
|
const { copy } = useCopy({ source: token, text: 'Token copied to the clipboard' });
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue