Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 01668eb

Browse files
fix: restrict filtering when not logged in
1 parent c804674 commit 01668eb

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/renderer/components/Filters/Filters.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ import {
2323
LanguageEnumeration,
2424
LibraryEnumeration,
2525
} from '../../types/assistantTypes';
26+
import { useUser } from '../UserContext';
2627

2728
export default function Filters() {
29+
const { id: userId } = useUser();
30+
const isAuthenticated = !!userId;
31+
2832
const { isOpen, onToggle } = useDisclosure();
2933
const {
3034
searchTerm,
@@ -104,6 +108,7 @@ export default function Filters() {
104108
/>
105109
<Flex flexWrap="nowrap" gridRowGap="0" gridColumnGap="space_16">
106110
<Radio
111+
isDisabled={!isAuthenticated}
107112
isChecked={privacy === 'all'}
108113
onChange={() => setPrivacy('all')}
109114
mb={0}
@@ -113,6 +118,7 @@ export default function Filters() {
113118
</Text>
114119
</Radio>
115120
<Radio
121+
isDisabled={!isAuthenticated}
116122
isChecked={privacy === 'public'}
117123
onChange={() => setPrivacy('public')}
118124
mb={0}
@@ -122,6 +128,7 @@ export default function Filters() {
122128
</Text>
123129
</Radio>
124130
<Radio
131+
isDisabled={!isAuthenticated}
125132
isChecked={privacy === 'private'}
126133
onChange={() => setPrivacy('private')}
127134
mb={0}
@@ -131,6 +138,7 @@ export default function Filters() {
131138
</Text>
132139
</Radio>
133140
<Checkbox
141+
isDisabled={!isAuthenticated}
134142
checked={isSubscribed}
135143
onChange={(e) => setIsSubscribed(e.target.checked)}
136144
mb={0}

src/renderer/hooks/useQueryVariables.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import { useUser } from '../components/UserContext';
12
import {
23
GET_USER_RECIPES_VARIABLES,
34
GET_USER_SUBSCRIBED_RECIPES_VARIABLES,
45
GET_SHARED_RECIPES_VARIABLES,
56
GET_USER_COOKBOOKS_VARIABLES,
67
GET_USER_SUBSCRIBED_COOKBOOKS_VARIABLES,
78
GET_SHARED_COOKBOOKS_VARIABLES,
8-
} from 'renderer/graphql/variables';
9-
import { Language } from 'renderer/lib/constants';
10-
import { LanguageEnumeration } from 'renderer/types/assistantTypes';
9+
} from '../graphql/variables';
10+
import { Language } from '../lib/constants';
11+
import { LanguageEnumeration } from '../types/assistantTypes';
1112
import { useFilters } from '../components/FiltersContext';
1213

1314
type QueryTypes =
@@ -21,6 +22,7 @@ type QueryTypes =
2122

2223
export default function useQueryVariables(query: QueryTypes) {
2324
const filters = useFilters();
25+
const { id: userId } = useUser();
2426

2527
switch (query) {
2628
case 'home':
@@ -34,9 +36,9 @@ export default function useQueryVariables(query: QueryTypes) {
3436
dependencies: filters.library ? [filters.library] : null,
3537
term: filters.searchTerm || null,
3638
tags: filters.tags ? [filters.tags] : null,
37-
onlyPrivate: filters.privacy === 'private' ? true : null,
38-
onlyPublic: filters.privacy === 'public' ? true : null,
39-
onlySubscribed: filters.isSubscribed || null,
39+
onlyPrivate: filters.privacy === 'private' && !!userId ? true : null,
40+
onlyPublic: filters.privacy === 'public' && !!userId ? true : null,
41+
onlySubscribed: userId ? filters.isSubscribed || null : null,
4042
};
4143

4244
case 'my-snippets':

0 commit comments

Comments
 (0)