-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Toggl-track] Update toggl-track extension (#15600)
* Update toggl-track extension - Fix lint and update changelog - Add UpdateTimeEntry command and update and remove time entry functionality - Initial commit * Update CHANGELOG.md * Update CHANGELOG.md and optimise images --------- Co-authored-by: Per Nielsen Tikær <[email protected]> Co-authored-by: raycastbot <[email protected]>
- Loading branch information
1 parent
324853f
commit e2d083c
Showing
9 changed files
with
402 additions
and
3 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
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
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,46 @@ | ||
import { ActionPanel, Icon, List } from "@raycast/api"; | ||
|
||
import { TimeEntry, TimeEntryMetaData } from "@/api"; | ||
import { formatSeconds } from "@/helpers/formatSeconds"; | ||
|
||
interface TimeEntriesListProps { | ||
isLoading: boolean; | ||
timeEntries: (TimeEntry & TimeEntryMetaData)[]; | ||
navigationTitle?: string; | ||
sectionTitle?: string; | ||
renderActions: (timeEntry: TimeEntry & TimeEntryMetaData) => JSX.Element; | ||
} | ||
|
||
export function TimeEntriesList({ | ||
isLoading, | ||
timeEntries, | ||
navigationTitle, | ||
sectionTitle = "Recent time entries", | ||
renderActions, | ||
}: TimeEntriesListProps) { | ||
return ( | ||
<List isLoading={isLoading} throttle navigationTitle={navigationTitle}> | ||
{timeEntries.length > 0 && ( | ||
<List.Section title={sectionTitle}> | ||
{timeEntries.map((timeEntry) => ( | ||
<List.Item | ||
key={timeEntry.id} | ||
keywords={[timeEntry.description, timeEntry.project_name || "", timeEntry.client_name || ""]} | ||
title={timeEntry.description || "No description"} | ||
subtitle={(timeEntry.client_name ? timeEntry.client_name + " | " : "") + (timeEntry.project_name ?? "")} | ||
accessories={[ | ||
{ text: formatSeconds(timeEntry.duration) }, | ||
...timeEntry.tags.map((tag) => ({ tag })), | ||
timeEntry.billable ? { tag: { value: "$" } } : {}, | ||
]} | ||
icon={{ source: Icon.Circle, tintColor: timeEntry.project_color }} | ||
actions={<ActionPanel>{renderActions(timeEntry)}</ActionPanel>} | ||
/> | ||
))} | ||
</List.Section> | ||
)} | ||
</List> | ||
); | ||
} | ||
|
||
export default TimeEntriesList; |
92 changes: 92 additions & 0 deletions
92
extensions/toggl-track/src/components/TimeEntriesListView.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,92 @@ | ||
import { Action, ActionPanel, Alert, Color, Icon, List, confirmAlert } from "@raycast/api"; | ||
|
||
import { removeTimeEntry } from "@/api"; | ||
import { ExtensionContextProvider } from "@/context/ExtensionContext"; | ||
import { formatSeconds } from "@/helpers/formatSeconds"; | ||
import { Verb, withToast } from "@/helpers/withToast"; | ||
import { useProcessedTimeEntries } from "@/hooks/useProcessedTimeEntries"; | ||
import { useTotalDurationToday } from "@/hooks/useTotalDurationToday"; | ||
|
||
import UpdateTimeEntryForm from "./UpdateTimeEntryForm"; | ||
|
||
export function TimeEntriesListView() { | ||
const { | ||
isLoading, | ||
mutateTimeEntries, | ||
timeEntries, | ||
timeEntriesWithUniqueProjectAndDescription, | ||
revalidateTimeEntries, | ||
} = useProcessedTimeEntries(); | ||
|
||
const totalDurationToday = useTotalDurationToday(timeEntries); | ||
|
||
return ( | ||
<List | ||
isLoading={isLoading} | ||
throttle | ||
navigationTitle={isLoading ? undefined : `Total: ${formatSeconds(totalDurationToday)}`} | ||
> | ||
{timeEntriesWithUniqueProjectAndDescription.length > 0 && ( | ||
<List.Section title="Recent time entries"> | ||
{timeEntriesWithUniqueProjectAndDescription.map((timeEntry) => ( | ||
<List.Item | ||
key={timeEntry.id} | ||
keywords={[timeEntry.description, timeEntry.project_name || "", timeEntry.client_name || ""]} | ||
title={timeEntry.description || "No description"} | ||
subtitle={(timeEntry.client_name ? timeEntry.client_name + " | " : "") + (timeEntry.project_name ?? "")} | ||
accessories={[ | ||
{ text: formatSeconds(timeEntry.duration) }, | ||
...timeEntry.tags.map((tag) => ({ tag })), | ||
timeEntry.billable ? { tag: { value: "$" } } : {}, | ||
]} | ||
icon={{ source: Icon.Circle, tintColor: timeEntry.project_color }} | ||
actions={ | ||
<ActionPanel> | ||
<Action.Push | ||
title="Edit Time Entry" | ||
icon={Icon.Pencil} | ||
target={ | ||
<ExtensionContextProvider> | ||
<UpdateTimeEntryForm timeEntry={timeEntry} revalidateTimeEntries={revalidateTimeEntries} /> | ||
</ExtensionContextProvider> | ||
} | ||
/> | ||
<ActionPanel.Section> | ||
<Action | ||
title="Delete Time Entry" | ||
icon={Icon.Trash} | ||
style={Action.Style.Destructive} | ||
shortcut={{ modifiers: ["ctrl"], key: "x" }} | ||
onAction={async () => { | ||
await confirmAlert({ | ||
title: "Delete Time Entry", | ||
message: "Are you sure you want to delete this time entry?", | ||
icon: { source: Icon.Trash, tintColor: Color.Red }, | ||
primaryAction: { | ||
title: "Delete", | ||
style: Alert.ActionStyle.Destructive, | ||
onAction: () => { | ||
withToast({ | ||
noun: "Time Entry", | ||
verb: Verb.Delete, | ||
action: async () => { | ||
await mutateTimeEntries(removeTimeEntry(timeEntry.workspace_id, timeEntry.id)); | ||
}, | ||
}); | ||
}, | ||
}, | ||
}); | ||
}} | ||
/> | ||
</ActionPanel.Section> | ||
</ActionPanel> | ||
} | ||
/> | ||
))} | ||
</List.Section> | ||
)} | ||
</List> | ||
); | ||
} | ||
|
||
export default TimeEntriesListView; |
Oops, something went wrong.