refactor(token-generator): now using computedRefreshable

This commit is contained in:
Corentin Thomasset 2023-03-29 21:12:20 +02:00
parent f6237376e1
commit cf16cb195d
No known key found for this signature in database
GPG key ID: DBD997E935996158

View file

@ -53,28 +53,25 @@
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
import { ref, watch } from 'vue';
import { useQueryParam } from '@/composable/queryParams';
import { computedRefreshable } from '@/composable/computedRefreshable';
import { createToken } from './token-generator.service';
const token = ref('');
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 withLowercase = useQueryParam({ name: 'lowercase', defaultValue: true });
const withNumbers = useQueryParam({ name: 'numbers', defaultValue: true });
const withSymbols = useQueryParam({ name: 'symbols', defaultValue: false });
watch([withUppercase, withLowercase, withNumbers, withSymbols, length], refreshToken, { immediate: true });
function refreshToken() {
token.value = createToken({
const [token, refreshToken] = computedRefreshable(() =>
createToken({
length: length.value,
withUppercase: withUppercase.value,
withLowercase: withLowercase.value,
withNumbers: withNumbers.value,
withSymbols: withSymbols.value,
});
}
}),
);
const { copy } = useCopy({ source: token, text: 'Token copied to the clipboard' });
</script>