1
0

fix: merge duplicate types

This commit is contained in:
Dominik Pschenitschni
2022-07-21 19:16:13 +02:00
parent 3ba423ed23
commit 106abfc842
3 changed files with 36 additions and 39 deletions

View File

@ -1,5 +1,6 @@
import {parseDate} from '../helpers/time/parseDate'
import {PRIORITIES} from '@/models/constants/priorities'
import {REPEAT_TYPES, type IRepeats, type RepeatType} from '@/types/IRepeats'
const VIKUNJA_PREFIXES: Prefixes = {
label: '*',
@ -27,24 +28,9 @@ export const PREFIXES = {
[PrefixMode.Todoist]: TODOIST_PREFIXES,
}
const priorities = PRIORITIES
enum RepeatType {
Hours = 'hours',
Days = 'days',
Weeks = 'weeks',
Months = 'months',
Years = 'years',
}
interface Repeats {
type: RepeatType,
amount: number,
}
interface repeatParsedResult {
textWithoutMatched: string,
repeats: Repeats | null,
repeats: IRepeats | null,
}
export interface ParsedTaskText {
@ -54,7 +40,7 @@ export interface ParsedTaskText {
list: string | null,
priority: number | null,
assignees: string[],
repeats: Repeats | null,
repeats: IRepeats | null,
}
interface Prefixes {
@ -144,7 +130,7 @@ const getPriority = (text: string, prefix: string): number | null => {
}
for (const p of ps) {
for (const pi of Object.values(priorities)) {
for (const pi of Object.values(PRIORITIES)) {
if (pi === parseInt(p)) {
return parseInt(p)
}
@ -199,55 +185,55 @@ const getRepeats = (text: string): repeatParsedResult => {
default:
amount = results[3] ? parseInt(results[3]) : 1
}
let type: RepeatType = RepeatType.Hours
let type: RepeatType = REPEAT_TYPES.Hours
switch (results[0]) {
case 'biennially':
type = RepeatType.Years
type = REPEAT_TYPES.Years
amount = 2
break
case 'bianually':
case 'semiannually':
type = RepeatType.Months
type = REPEAT_TYPES.Months
amount = 6
break
case 'yearly':
case 'anually':
type = RepeatType.Years
type = REPEAT_TYPES.Years
break
case 'daily':
type = RepeatType.Days
type = REPEAT_TYPES.Days
break
case 'hourly':
type = RepeatType.Hours
type = REPEAT_TYPES.Hours
break
case 'monthly':
type = RepeatType.Months
type = REPEAT_TYPES.Months
break
case 'weekly':
type = RepeatType.Weeks
type = REPEAT_TYPES.Weeks
break
default:
switch (results[5]) {
case 'hour':
case 'hours':
type = RepeatType.Hours
type = REPEAT_TYPES.Hours
break
case 'day':
case 'days':
type = RepeatType.Days
type = REPEAT_TYPES.Days
break
case 'week':
case 'weeks':
type = RepeatType.Weeks
type = REPEAT_TYPES.Weeks
break
case 'month':
case 'months':
type = RepeatType.Months
type = REPEAT_TYPES.Months
break
case 'year':
case 'years':
type = RepeatType.Years
type = REPEAT_TYPES.Years
break
}
}