refactor(UserSchedule): index by a unique id rather than name (#166)
* refactor(UserSchedule): index by a unique id rather than name * refactor: Update parameter names in schedule function jsdocs * refactor: change more instances of .name to .id * refactor: Fix typo in variable name and update references * refactor: Remove console.log statement * fix(chromatic): Update ScheduleListItem story * refactor: remove unused eslint rule
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { UserScheduleStore } from '@shared/storage/UserScheduleStore';
|
||||
import { UserSchedule } from '@shared/types/UserSchedule';
|
||||
import { generateRandomId } from '@shared/util/random';
|
||||
import type { Meta, StoryObj } from '@storybook/react';
|
||||
import List from '@views/components/common/List/List';
|
||||
import ScheduleDropdown from '@views/components/common/ScheduleDropdown/ScheduleDropdown';
|
||||
@@ -14,6 +15,7 @@ const schedules: UserSchedule[] = new Array(10).fill(exampleSchedule).map(
|
||||
(schedule: UserSchedule, index) =>
|
||||
new UserSchedule({
|
||||
...schedule,
|
||||
id: generateRandomId(),
|
||||
name: `Schedule ${index + 1}`,
|
||||
})
|
||||
);
|
||||
@@ -61,10 +63,10 @@ const meta: Meta<typeof ScheduleDropdown> = {
|
||||
<ScheduleDropdown {...args}>
|
||||
<List
|
||||
draggables={schedules}
|
||||
equalityCheck={(a, b) => a.name === b.name}
|
||||
itemKey={s => s.id}
|
||||
onReordered={reordered => {
|
||||
const activeSchedule = getActiveSchedule();
|
||||
const activeIndex = reordered.findIndex(s => s.name === activeSchedule.name);
|
||||
const activeIndex = reordered.findIndex(s => s.id === activeSchedule.id);
|
||||
|
||||
// don't care about the promise
|
||||
UserScheduleStore.set('schedules', reordered);
|
||||
@@ -74,9 +76,9 @@ const meta: Meta<typeof ScheduleDropdown> = {
|
||||
>
|
||||
{(schedule, handleProps) => (
|
||||
<ScheduleListItem
|
||||
name={schedule.name}
|
||||
schedule={schedule}
|
||||
onClick={() => {
|
||||
switchSchedule(schedule.name);
|
||||
switchSchedule(schedule.id);
|
||||
}}
|
||||
dragHandleProps={handleProps}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user