Skip to content

Commit

Permalink
proper cache invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgraf committed Jun 6, 2024
1 parent a3be3c5 commit ff448cf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ Users use OPAQUE to authenticate with the server. After Login the server creates

## Todos

- invalidate documentsQuery properly

- add invitation scheme
- allow to delete list
- allow to delete list (needs a tombstone)

- add retry for locker in case write fails (invalid clock)
- store the list name locally (also with unsynced changes)
Expand Down
3 changes: 3 additions & 0 deletions apps/app/src/app/list/[listId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ const List: React.FC<Props> = () => {
placeholder="What needs to be done?"
onChangeText={(value) => setNewTodoText(value)}
value={newTodoText}
autoCapitalize="none"
autoCorrect={false}
autoComplete="off"
/>
<Button
className="add"
Expand Down
4 changes: 4 additions & 0 deletions apps/app/src/components/authForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const AuthForm = ({ onSubmit, isPending, children }: Props) => {
className="border border-slate-300 p-2 rounded"
placeholder="Username"
autoComplete="off"
autoCorrect={false}
autoCapitalize="none"
value={username}
onChangeText={(value) => {
setUsername(value);
Expand All @@ -37,6 +39,8 @@ export const AuthForm = ({ onSubmit, isPending, children }: Props) => {
className="border border-slate-300 p-2 rounded"
placeholder="Password"
autoComplete="off"
autoCorrect={false}
autoCapitalize="none"
value={password}
onChangeText={(value) => {
setPassword(value);
Expand Down
13 changes: 12 additions & 1 deletion apps/app/src/components/createListForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useQueryClient } from "@tanstack/react-query";
import { getQueryKey } from "@trpc/react-query";
import { router } from "expo-router";
import { Alert, View } from "react-native";
import * as sodium from "react-native-libsodium";
Expand All @@ -12,13 +14,15 @@ export const CreateListForm: React.FC = () => {
// const [name, setName] = useState("");
const createDocumentMutation = trpc.createDocument.useMutation();
const { addItem } = useLocker();
const queryClient = useQueryClient();

return (
<View className="flex justify-center items-center gap-4 py-4">
{/* <Input
placeholder="List name"
className="max-w-48"
value={name}
autoCorrect={false}
onChangeText={(value) => {
setName(value);
}}
Expand Down Expand Up @@ -58,7 +62,14 @@ export const CreateListForm: React.FC = () => {
pathname: `/list/[documentId]`,
params: { documentId: document.id },
});
// documentsQuery.refetch(); // TODO
const documentsQueryKey = getQueryKey(
trpc.documents,
undefined,
"query"
);
queryClient.invalidateQueries({
queryKey: [documentsQueryKey],
});
},
onError: () => {
Alert.alert("Failed to create the list");
Expand Down
9 changes: 9 additions & 0 deletions apps/app/src/components/updateDocumentNameForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useQueryClient } from "@tanstack/react-query";
import { getQueryKey } from "@trpc/react-query";
import { useEffect, useState } from "react";
import { View } from "react-native";
import { Input } from "~/components/ui/input";
Expand All @@ -15,6 +17,7 @@ export const UpdateDocumentNameForm = ({ documentId, documentKey }: Props) => {

const getDocumentQuery = trpc.getDocument.useQuery(documentId);
const updateDocumentMutation = trpc.updateDocument.useMutation();
const queryClient = useQueryClient();

useEffect(() => {
if (getDocumentQuery.data) {
Expand All @@ -40,6 +43,10 @@ export const UpdateDocumentNameForm = ({ documentId, documentKey }: Props) => {
nameNonce: nonce,
nameCommitment: commitment,
});
const documentsQueryKey = getQueryKey(trpc.documents, undefined, "query");
queryClient.invalidateQueries({
queryKey: [documentsQueryKey],
});
};

return (
Expand All @@ -49,6 +56,8 @@ export const UpdateDocumentNameForm = ({ documentId, documentKey }: Props) => {
className="border border-slate-300 p-2 rounded"
placeholder="List name"
autoComplete="off"
autoCorrect={false}
autoCapitalize="none"
value={name}
onChangeText={(value) => {
setName(value);
Expand Down

0 comments on commit ff448cf

Please sign in to comment.