forked from raycast/extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add recurrent reminders (raycast#12208)
- Loading branch information
Showing
12 changed files
with
218 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
extensions/simple-reminder/src/components/listActionPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Action, ActionPanel, Color, Icon } from "@raycast/api"; | ||
import { Frequency } from "../types/frequency"; | ||
import { Reminder } from "../types/reminder"; | ||
|
||
type ActionPanelProps = { | ||
searchText: string; | ||
reminder: Reminder; | ||
onSetReminderAction: () => void; | ||
onSetRecurrenceForReminderAction: (reminderId: string, frequency: Frequency) => void; | ||
onCopyReminderTopicAction: (reminderTopic: string) => void; | ||
onDeleteReminderAction: (reminderId: string) => void; | ||
}; | ||
|
||
export function ListActionPanel({ | ||
searchText, | ||
reminder, | ||
onSetReminderAction, | ||
onSetRecurrenceForReminderAction, | ||
onCopyReminderTopicAction, | ||
onDeleteReminderAction, | ||
}: ActionPanelProps) { | ||
return ( | ||
<ActionPanel> | ||
{searchText.length > 0 && <Action title="Set Reminder" icon={Icon.AlarmRinging} onAction={onSetReminderAction} />} | ||
{!reminder.frequency && ( | ||
<ActionPanel.Submenu title="Set Recurrence" icon={Icon.Repeat}> | ||
<Action | ||
icon={{ source: Icon.Repeat, tintColor: Color.Red }} | ||
title="Daily" | ||
onAction={() => onSetRecurrenceForReminderAction(reminder.id, Frequency.DAILY)} | ||
/> | ||
<Action | ||
icon={{ source: Icon.Repeat, tintColor: Color.Orange }} | ||
title="Weekly" | ||
onAction={() => onSetRecurrenceForReminderAction(reminder.id, Frequency.WEEKLY)} | ||
/> | ||
<Action | ||
icon={{ source: Icon.Repeat, tintColor: Color.Yellow }} | ||
title="Bi-Weekly" | ||
onAction={() => onSetRecurrenceForReminderAction(reminder.id, Frequency.BI_WEEKLY)} | ||
/> | ||
<Action | ||
icon={{ source: Icon.Repeat, tintColor: Color.Green }} | ||
title="Monthly" | ||
onAction={() => onSetRecurrenceForReminderAction(reminder.id, Frequency.MONTHLY)} | ||
/> | ||
</ActionPanel.Submenu> | ||
)} | ||
<Action | ||
title="Copy to Clipboard" | ||
icon={Icon.CopyClipboard} | ||
shortcut={{ modifiers: ["cmd", "shift"], key: "c" }} | ||
onAction={() => onCopyReminderTopicAction(reminder.topic)} | ||
/> | ||
<Action | ||
title="Delete Reminder" | ||
style={Action.Style.Destructive} | ||
icon={Icon.Trash} | ||
shortcut={{ modifiers: ["cmd", "shift"], key: "backspace" }} | ||
onAction={() => onDeleteReminderAction(reminder.id)} | ||
/> | ||
</ActionPanel> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
extensions/simple-reminder/src/handlers/setRecurrenceForReminder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { LocalStorage } from "@raycast/api"; | ||
import { Frequency } from "../types/frequency"; | ||
import { Reminder } from "../types/reminder"; | ||
|
||
type SetRecurrenceForReminderProps = { | ||
reminderId: string; | ||
frequency: Frequency; | ||
existingReminders: Reminder[]; | ||
setReminders: (reminders: Reminder[]) => void; | ||
}; | ||
|
||
export async function setRecurrenceForReminder(props: SetRecurrenceForReminderProps) { | ||
const reminder: Reminder = props.existingReminders.find((reminder) => reminder.id === props.reminderId)!; | ||
reminder.frequency = props.frequency; | ||
props.setReminders([...props.existingReminders]); | ||
await LocalStorage.setItem(reminder.id, JSON.stringify(reminder)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum Frequency { | ||
DAILY = "daily", | ||
WEEKLY = "weekly", | ||
BI_WEEKLY = "bi-weekly", | ||
MONTHLY = "monthly", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface SimpleReminderPreferences { | ||
mobileNotificationNtfy: boolean; | ||
mobileNotificationNtfyTopic: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { Frequency } from "./frequency"; | ||
|
||
export type Reminder = { | ||
id: string; | ||
topic: string; | ||
date: Date; | ||
frequency?: Frequency; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Reminder } from "../types/reminder"; | ||
|
||
export function hasFrequencyPredicate(reminder: Reminder) { | ||
return !!reminder.frequency; | ||
} | ||
|
||
export function hasNoFrequencyPredicate(reminder: Reminder) { | ||
return !reminder.frequency; | ||
} |