mirror of
https://github.com/immich-app/immich.git
synced 2024-11-24 08:52:28 +02:00
chore(web): simpler unique ID generation (#9945)
This commit is contained in:
parent
d1135db8cf
commit
1323c7ee88
@ -18,8 +18,8 @@
|
||||
import { shortcuts } from '$lib/actions/shortcut';
|
||||
import { clickOutside } from '$lib/actions/click-outside';
|
||||
import { focusOutside } from '$lib/actions/focus-outside';
|
||||
import { generateId } from '$lib/utils/generate-id';
|
||||
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
||||
import { uniqueIdStore } from '$lib/stores/unique-id.store';
|
||||
|
||||
export let label: string;
|
||||
export let hideLabel = false;
|
||||
@ -30,7 +30,7 @@
|
||||
/**
|
||||
* Unique identifier for the combobox.
|
||||
*/
|
||||
let id: string = uniqueIdStore.generateId();
|
||||
let id: string = generateId();
|
||||
/**
|
||||
* Indicates whether or not the dropdown autocomplete list should be visible.
|
||||
*/
|
||||
|
@ -3,7 +3,7 @@
|
||||
import { fade } from 'svelte/transition';
|
||||
import FocusTrap from '$lib/components/shared-components/focus-trap.svelte';
|
||||
import ModalHeader from '$lib/components/shared-components/modal-header.svelte';
|
||||
import { uniqueIdStore } from '$lib/stores/unique-id.store';
|
||||
import { generateId } from '$lib/utils/generate-id';
|
||||
|
||||
export let onClose: () => void;
|
||||
export let title: string;
|
||||
@ -27,7 +27,7 @@
|
||||
/**
|
||||
* Unique identifier for the modal.
|
||||
*/
|
||||
let id: string = uniqueIdStore.generateId();
|
||||
let id: string = generateId();
|
||||
|
||||
$: titleId = `${id}-title`;
|
||||
$: isStickyBottom = !!$$slots['sticky-bottom'];
|
||||
|
@ -3,7 +3,7 @@
|
||||
import { fly } from 'svelte/transition';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import Slider from '$lib/components/elements/slider.svelte';
|
||||
import { uniqueIdStore } from '$lib/stores/unique-id.store';
|
||||
import { generateId } from '$lib/utils/generate-id';
|
||||
|
||||
export let title: string;
|
||||
export let subtitle = '';
|
||||
@ -11,7 +11,7 @@
|
||||
export let disabled = false;
|
||||
export let isEdited = false;
|
||||
|
||||
let id: string = uniqueIdStore.generateId();
|
||||
let id: string = generateId();
|
||||
|
||||
$: sliderId = `${id}-slider`;
|
||||
$: subtitleId = subtitle ? `${id}-subtitle` : undefined;
|
||||
|
@ -1,14 +0,0 @@
|
||||
import { uniqueIdStore } from '$lib/stores/unique-id.store';
|
||||
|
||||
describe('uniqueIdStore', () => {
|
||||
afterEach(() => {
|
||||
uniqueIdStore.update(() => -1);
|
||||
});
|
||||
|
||||
it('should generate unique ids', () => {
|
||||
const { generateId } = uniqueIdStore;
|
||||
const ids = [generateId(), generateId(), generateId()];
|
||||
|
||||
expect(ids).toEqual(['id-0', 'id-1', 'id-2']);
|
||||
});
|
||||
});
|
@ -1,16 +0,0 @@
|
||||
import { get, writable } from 'svelte/store';
|
||||
|
||||
function createIdStore() {
|
||||
const { subscribe, update } = writable(-1);
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
update,
|
||||
generateId: () => {
|
||||
update((value) => value + 1);
|
||||
return `id-${get(uniqueIdStore)}`;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const uniqueIdStore = createIdStore();
|
2
web/src/lib/utils/generate-id.ts
Normal file
2
web/src/lib/utils/generate-id.ts
Normal file
@ -0,0 +1,2 @@
|
||||
let _count = 0;
|
||||
export const generateId = (): string => `id-${_count++}`;
|
Loading…
Reference in New Issue
Block a user