Skip to content

Commit

Permalink
Merge branch 'main' into bcrypt-error-states
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel-rowe authored Aug 9, 2024
2 parents 40fec6a + e1b4f9a commit 52f4986
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,6 @@
"vitest": "^0.34.0",
"workbox-window": "^7.0.0",
"zx": "^7.2.1"
}
},
"packageManager": "[email protected]"
}
21 changes: 21 additions & 0 deletions src/composable/debouncedref.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import _ from 'lodash';

function useDebouncedRef<T>(initialValue: T, delay: number, immediate: boolean = false) {
const state = ref(initialValue);
const debouncedRef = customRef((track, trigger) => ({
get() {
track();
return state.value;
},
set: _.debounce(
(value) => {
state.value = value;
trigger();
},
delay,
{ leading: immediate },
),
}));
return debouncedRef;
}
export default useDebouncedRef;
3 changes: 2 additions & 1 deletion src/tools/emoji-picker/emoji-picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import emojiKeywords from 'emojilib';
import _ from 'lodash';
import type { EmojiInfo } from './emoji.types';
import { useFuzzySearch } from '@/composable/fuzzySearch';
import useDebouncedRef from '@/composable/debouncedref';
const escapeUnicode = ({ emoji }: { emoji: string }) => emoji.split('').map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, '0')}`).join('');
const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji.codePointAt(0) ? `0x${emoji.codePointAt(0)?.toString(16)}` : undefined;
Expand All @@ -23,7 +24,7 @@ const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _
.map((emojiInfos, group) => ({ group, emojiInfos }))
.value();
const searchQuery = ref('');
const searchQuery = useDebouncedRef('', 500);
const { searchResult } = useFuzzySearch({
search: searchQuery,
Expand Down
9 changes: 7 additions & 2 deletions src/tools/lorem-ipsum-generator/lorem-ipsum-generator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import { generateLoremIpsum } from './lorem-ipsum-generator.service';
import { useCopy } from '@/composable/copy';
import { randIntFromInterval } from '@/utils/random';
import { computedRefreshable } from '@/composable/computedRefreshable';
const paragraphs = ref(1);
const sentences = ref([3, 8]);
const words = ref([8, 15]);
const startWithLoremIpsum = ref(true);
const asHTML = ref(false);
const loremIpsumText = computed(() =>
const [loremIpsumText, refreshLoremIpsum] = computedRefreshable(() =>
generateLoremIpsum({
paragraphCount: paragraphs.value,
asHTML: asHTML.value,
Expand All @@ -18,6 +19,7 @@ const loremIpsumText = computed(() =>
startWithLoremIpsum: startWithLoremIpsum.value,
}),
);
const { copy } = useCopy({ source: loremIpsumText, text: 'Lorem ipsum copied to the clipboard' });
</script>

Expand All @@ -41,10 +43,13 @@ const { copy } = useCopy({ source: loremIpsumText, text: 'Lorem ipsum copied to

<c-input-text :value="loremIpsumText" multiline placeholder="Your lorem ipsum..." readonly mt-5 rows="5" />

<div mt-5 flex justify-center>
<div mt-5 flex justify-center gap-3>
<c-button autofocus @click="copy()">
Copy
</c-button>
<c-button @click="refreshLoremIpsum">
Refresh
</c-button>
</div>
</c-card>
</template>

0 comments on commit 52f4986

Please sign in to comment.