feat: report issue popup (#261)
* feat: report issue popup * style: modified styles in feedback form * chore: minor UI fixes * chore: update useEffect * chore: change width to 400px --------- Co-authored-by: doprz <52579214+doprz@users.noreply.github.com> Co-authored-by: Isaiah David Rodriguez <51803892+IsaDavRod@users.noreply.github.com>
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { UserScheduleStore } from '@shared/storage/UserScheduleStore';
|
||||
import { generateRandomId } from '@shared/util/random';
|
||||
|
||||
import handleDuplicate from './handleDuplicate';
|
||||
|
||||
/**
|
||||
* Creates a new schedule with the given name
|
||||
* @param scheduleName the name of the schedule to create
|
||||
@@ -10,13 +8,23 @@ import handleDuplicate from './handleDuplicate';
|
||||
*/
|
||||
export default async function createSchedule(scheduleName: string): Promise<string | undefined> {
|
||||
const schedules = await UserScheduleStore.get('schedules');
|
||||
// get the number of schedules that either have the same name or have the same name with a number appended (e.g. "New Schedule (1)")
|
||||
// this way we can prevent duplicate schedule names and increment the number if necessary
|
||||
|
||||
// Duplicate schedule found, we need to append a number to the end of the schedule name
|
||||
const updatedName = await handleDuplicate(scheduleName);
|
||||
// Regex to match schedule names that follow the pattern "ScheduleName" or "ScheduleName (1)", "ScheduleName (2)", etc.
|
||||
const regex = new RegExp(`^${scheduleName}( \\(\\d+\\))?$`);
|
||||
|
||||
// Find how many schedules match the base name or follow the pattern with a number
|
||||
const count = schedules.filter(s => regex.test(s.name)).length;
|
||||
|
||||
// If any matches are found, append the next number to the schedule name
|
||||
let name = scheduleName;
|
||||
if (count > 0) {
|
||||
name = `${scheduleName} (${count})`;
|
||||
}
|
||||
schedules.push({
|
||||
id: generateRandomId(),
|
||||
name: updatedName,
|
||||
name,
|
||||
courses: [],
|
||||
hours: 0,
|
||||
updatedAt: Date.now(),
|
||||
|
||||
Reference in New Issue
Block a user