@greatapps/common 1.1.500 → 1.1.501

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,31 +10,39 @@ function useDeleteProject() {
10
10
  return useMutation({
11
11
  mutationFn: ({ projectId, moveToProjectId }) => withAction(deleteProjectAction)(projectId, moveToProjectId),
12
12
  onSuccess: (_, { projectId }) => {
13
- queryClient.setQueriesData(
14
- { queryKey: projectsKey, exact: false },
15
- (old) => {
16
- if (!old?.pages.length) return old;
17
- return {
18
- ...old,
19
- pages: old.pages.map((page) => ({
20
- ...page,
21
- data: page.data.filter((p) => p.id !== projectId),
22
- total: page.total - 1
23
- }))
24
- };
13
+ const cache = queryClient.getQueryCache();
14
+ const queries = cache.findAll({ queryKey: projectsKey });
15
+ for (const query of queries) {
16
+ const isInfinite = query.queryKey.includes("infinite");
17
+ if (isInfinite) {
18
+ queryClient.setQueryData(
19
+ query.queryKey,
20
+ (old) => {
21
+ if (!old?.pages.length) return old;
22
+ return {
23
+ ...old,
24
+ pages: old.pages.map((page) => ({
25
+ ...page,
26
+ data: page.data.filter((p) => p.id !== projectId),
27
+ total: page.total - 1
28
+ }))
29
+ };
30
+ }
31
+ );
32
+ } else {
33
+ queryClient.setQueryData(
34
+ query.queryKey,
35
+ (old) => {
36
+ if (!old) return old;
37
+ return {
38
+ ...old,
39
+ data: old.data.filter((p) => p.id !== projectId),
40
+ total: old.total - 1
41
+ };
42
+ }
43
+ );
25
44
  }
26
- );
27
- queryClient.setQueriesData(
28
- { queryKey: projectsKey, exact: false },
29
- (old) => {
30
- if (!old) return old;
31
- return {
32
- ...old,
33
- data: old.data.filter((p) => p.id !== projectId),
34
- total: old.total - 1
35
- };
36
- }
37
- );
45
+ }
38
46
  queryClient.invalidateQueries({ queryKey: projectsKey });
39
47
  }
40
48
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/projects/hooks/delete-project.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient, InfiniteData } from '@tanstack/react-query';\nimport { deleteProjectAction } from '../actions/delete-project.action';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { PROJECTS_BASE_KEY } from './list-projects.hook';\nimport type { ProjectsPage } from '../types';\n\nexport function useDeleteProject() {\n const queryClient = useQueryClient();\n const projectsKey = useAuthQueryKey([...PROJECTS_BASE_KEY]);\n\n return useMutation({\n mutationFn: ({ projectId, moveToProjectId }: { projectId: number; moveToProjectId: number }) =>\n withAction(deleteProjectAction)(projectId, moveToProjectId),\n\n onSuccess: (_, { projectId }) => {\n queryClient.setQueriesData<InfiniteData<ProjectsPage>>(\n { queryKey: projectsKey, exact: false },\n (old) => {\n if (!old?.pages.length) return old;\n return {\n ...old,\n pages: old.pages.map((page) => ({\n ...page,\n data: page.data.filter((p) => p.id !== projectId),\n total: page.total - 1,\n })),\n };\n },\n );\n\n queryClient.setQueriesData<ProjectsPage>(\n { queryKey: projectsKey, exact: false },\n (old) => {\n if (!old) return old;\n return {\n ...old,\n data: old.data.filter((p) => p.id !== projectId),\n total: old.total - 1,\n };\n },\n );\n\n queryClient.invalidateQueries({ queryKey: projectsKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAoC;AAC1D,SAAS,2BAA2B;AACpC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAG3B,SAAS,mBAAmB;AACjC,QAAM,cAAc,eAAe;AACnC,QAAM,cAAc,gBAAgB,CAAC,GAAG,iBAAiB,CAAC;AAE1D,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,EAAE,WAAW,gBAAgB,MACxC,WAAW,mBAAmB,EAAE,WAAW,eAAe;AAAA,IAE5D,WAAW,CAAC,GAAG,EAAE,UAAU,MAAM;AAC/B,kBAAY;AAAA,QACV,EAAE,UAAU,aAAa,OAAO,MAAM;AAAA,QACtC,CAAC,QAAQ;AACP,cAAI,CAAC,KAAK,MAAM,OAAQ,QAAO;AAC/B,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,OAAO,IAAI,MAAM,IAAI,CAAC,UAAU;AAAA,cAC9B,GAAG;AAAA,cACH,MAAM,KAAK,KAAK,OAAO,CAAC,MAAM,EAAE,OAAO,SAAS;AAAA,cAChD,OAAO,KAAK,QAAQ;AAAA,YACtB,EAAE;AAAA,UACJ;AAAA,QACF;AAAA,MACF;AAEA,kBAAY;AAAA,QACV,EAAE,UAAU,aAAa,OAAO,MAAM;AAAA,QACtC,CAAC,QAAQ;AACP,cAAI,CAAC,IAAK,QAAO;AACjB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,MAAM,IAAI,KAAK,OAAO,CAAC,MAAM,EAAE,OAAO,SAAS;AAAA,YAC/C,OAAO,IAAI,QAAQ;AAAA,UACrB;AAAA,QACF;AAAA,MACF;AAEA,kBAAY,kBAAkB,EAAE,UAAU,YAAY,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/projects/hooks/delete-project.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient, InfiniteData } from '@tanstack/react-query';\nimport { deleteProjectAction } from '../actions/delete-project.action';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { PROJECTS_BASE_KEY } from './list-projects.hook';\nimport type { ProjectsPage } from '../types';\n\nexport function useDeleteProject() {\n const queryClient = useQueryClient();\n const projectsKey = useAuthQueryKey([...PROJECTS_BASE_KEY]);\n\n return useMutation({\n mutationFn: ({ projectId, moveToProjectId }: { projectId: number; moveToProjectId: number }) =>\n withAction(deleteProjectAction)(projectId, moveToProjectId),\n\n onSuccess: (_, { projectId }) => {\n const cache = queryClient.getQueryCache();\n const queries = cache.findAll({ queryKey: projectsKey });\n\n for (const query of queries) {\n const isInfinite = query.queryKey.includes('infinite');\n\n if (isInfinite) {\n queryClient.setQueryData<InfiniteData<ProjectsPage>>(\n query.queryKey,\n (old) => {\n if (!old?.pages.length) return old;\n return {\n ...old,\n pages: old.pages.map((page) => ({\n ...page,\n data: page.data.filter((p) => p.id !== projectId),\n total: page.total - 1,\n })),\n };\n },\n );\n } else {\n queryClient.setQueryData<ProjectsPage>(\n query.queryKey,\n (old) => {\n if (!old) return old;\n return {\n ...old,\n data: old.data.filter((p) => p.id !== projectId),\n total: old.total - 1,\n };\n },\n );\n }\n }\n\n queryClient.invalidateQueries({ queryKey: projectsKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAoC;AAC1D,SAAS,2BAA2B;AACpC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAG3B,SAAS,mBAAmB;AACjC,QAAM,cAAc,eAAe;AACnC,QAAM,cAAc,gBAAgB,CAAC,GAAG,iBAAiB,CAAC;AAE1D,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,EAAE,WAAW,gBAAgB,MACxC,WAAW,mBAAmB,EAAE,WAAW,eAAe;AAAA,IAE5D,WAAW,CAAC,GAAG,EAAE,UAAU,MAAM;AAC/B,YAAM,QAAQ,YAAY,cAAc;AACxC,YAAM,UAAU,MAAM,QAAQ,EAAE,UAAU,YAAY,CAAC;AAEvD,iBAAW,SAAS,SAAS;AAC3B,cAAM,aAAa,MAAM,SAAS,SAAS,UAAU;AAErD,YAAI,YAAY;AACd,sBAAY;AAAA,YACV,MAAM;AAAA,YACN,CAAC,QAAQ;AACP,kBAAI,CAAC,KAAK,MAAM,OAAQ,QAAO;AAC/B,qBAAO;AAAA,gBACL,GAAG;AAAA,gBACH,OAAO,IAAI,MAAM,IAAI,CAAC,UAAU;AAAA,kBAC9B,GAAG;AAAA,kBACH,MAAM,KAAK,KAAK,OAAO,CAAC,MAAM,EAAE,OAAO,SAAS;AAAA,kBAChD,OAAO,KAAK,QAAQ;AAAA,gBACtB,EAAE;AAAA,cACJ;AAAA,YACF;AAAA,UACF;AAAA,QACF,OAAO;AACL,sBAAY;AAAA,YACV,MAAM;AAAA,YACN,CAAC,QAAQ;AACP,kBAAI,CAAC,IAAK,QAAO;AACjB,qBAAO;AAAA,gBACL,GAAG;AAAA,gBACH,MAAM,IAAI,KAAK,OAAO,CAAC,MAAM,EAAE,OAAO,SAAS;AAAA,gBAC/C,OAAO,IAAI,QAAQ;AAAA,cACrB;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,kBAAY,kBAAkB,EAAE,UAAU,YAAY,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/common",
3
- "version": "1.1.500",
3
+ "version": "1.1.501",
4
4
  "description": "Shared library for GreatApps frontend applications",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./src/index.ts",
@@ -16,32 +16,41 @@ export function useDeleteProject() {
16
16
  withAction(deleteProjectAction)(projectId, moveToProjectId),
17
17
 
18
18
  onSuccess: (_, { projectId }) => {
19
- queryClient.setQueriesData<InfiniteData<ProjectsPage>>(
20
- { queryKey: projectsKey, exact: false },
21
- (old) => {
22
- if (!old?.pages.length) return old;
23
- return {
24
- ...old,
25
- pages: old.pages.map((page) => ({
26
- ...page,
27
- data: page.data.filter((p) => p.id !== projectId),
28
- total: page.total - 1,
29
- })),
30
- };
31
- },
32
- );
19
+ const cache = queryClient.getQueryCache();
20
+ const queries = cache.findAll({ queryKey: projectsKey });
33
21
 
34
- queryClient.setQueriesData<ProjectsPage>(
35
- { queryKey: projectsKey, exact: false },
36
- (old) => {
37
- if (!old) return old;
38
- return {
39
- ...old,
40
- data: old.data.filter((p) => p.id !== projectId),
41
- total: old.total - 1,
42
- };
43
- },
44
- );
22
+ for (const query of queries) {
23
+ const isInfinite = query.queryKey.includes('infinite');
24
+
25
+ if (isInfinite) {
26
+ queryClient.setQueryData<InfiniteData<ProjectsPage>>(
27
+ query.queryKey,
28
+ (old) => {
29
+ if (!old?.pages.length) return old;
30
+ return {
31
+ ...old,
32
+ pages: old.pages.map((page) => ({
33
+ ...page,
34
+ data: page.data.filter((p) => p.id !== projectId),
35
+ total: page.total - 1,
36
+ })),
37
+ };
38
+ },
39
+ );
40
+ } else {
41
+ queryClient.setQueryData<ProjectsPage>(
42
+ query.queryKey,
43
+ (old) => {
44
+ if (!old) return old;
45
+ return {
46
+ ...old,
47
+ data: old.data.filter((p) => p.id !== projectId),
48
+ total: old.total - 1,
49
+ };
50
+ },
51
+ );
52
+ }
53
+ }
45
54
 
46
55
  queryClient.invalidateQueries({ queryKey: projectsKey });
47
56
  },