[24.0] Fix hasOwner function for histories in client

The `hasOwner` function in `api/index.ts` was checking:
```
return "user_id" in history;
```

whereas, it also needed to check:
```
return "user_id" in history && history.user_id !== null;
```

because we assume histories (summaries) initally fetched for the `historyStore` without user_id are owned by the current user, but the key is still present in the backend return.

This was causing a really troublesome bug in the `HistoryScrollList` found in the history selector modal, where we could constantly keep fetching `api/histories/count` since we didn't have the expected no. of histories loaded in the component; because `historiesProxy` (which only contains owned histories) would end up being empty.
This commit is contained in:
Ahmed Awan
2024-04-02 12:19:50 -05:00
parent e331ccbca3
commit 09f77f4d4c
+1 -1
View File
@@ -228,5 +228,5 @@ export function userOwnsHistory(user: User | AnonymousUser | null, history: AnyH
}
function hasOwner(history: AnyHistory): history is HistorySummaryExtended {
return "user_id" in history;
return "user_id" in history && history.user_id !== null;
}