-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hotkeys for unslecting and deleting timespans (#148)
- Loading branch information
1 parent
b707a27
commit 6842b5c
Showing
3 changed files
with
122 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {RemoveTimeSpan, RemoveTimeSpanVariables} from '../gql/__generated__/RemoveTimeSpan'; | ||
import * as gqlTimeSpan from '../gql/timeSpan'; | ||
import {TimeSpans} from '../gql/__generated__/TimeSpans'; | ||
import {Trackers} from '../gql/__generated__/Trackers'; | ||
import {MutationHookOptions} from '@apollo/react-hooks/lib/types'; | ||
|
||
export const removeTimeSpanOptions: MutationHookOptions<RemoveTimeSpan, RemoveTimeSpanVariables> = { | ||
update: (cache, {data}) => { | ||
let oldData: TimeSpans | null = null; | ||
try { | ||
oldData = cache.readQuery<TimeSpans>({query: gqlTimeSpan.TimeSpans}); | ||
} catch (e) {} | ||
|
||
const oldTrackers = cache.readQuery<Trackers>({query: gqlTimeSpan.Trackers}); | ||
if (!data || !data.removeTimeSpan) { | ||
return; | ||
} | ||
const removedId = data.removeTimeSpan.id; | ||
if (oldTrackers) { | ||
cache.writeQuery<Trackers>({ | ||
query: gqlTimeSpan.Trackers, | ||
data: { | ||
timers: (oldTrackers.timers || []).filter((tracker) => tracker.id !== removedId), | ||
}, | ||
}); | ||
} | ||
if (oldData) { | ||
cache.writeQuery<TimeSpans>({ | ||
query: gqlTimeSpan.TimeSpans, | ||
data: { | ||
timeSpans: { | ||
__typename: 'PagedTimeSpans', | ||
timeSpans: oldData.timeSpans.timeSpans.filter((ts) => ts.id !== removedId), | ||
cursor: oldData.timeSpans.cursor, | ||
}, | ||
}, | ||
}); | ||
} | ||
}, | ||
}; |
I think here the backspace is a bad idea, as this doesn't allow the user to correct typos