Esteves Enzo commited on
Commit
6d2113a
·
1 Parent(s): 2f246c6

infinite scroll + fix nsfw check + input doesnt allow to edit

Browse files
app/api/route.ts CHANGED
@@ -41,16 +41,14 @@ export async function POST(
41
  const isNSFW = await response_nsfw.clone().json().catch(() => ({}));
42
 
43
  if (isNSFW?.error && isNSFW?.estimated_time) {
44
- console.log("retrying...")
45
  setTimeout(() => {
46
  checkIfIsNSFW(blob)
47
- }, isNSFW?.estimated_time * 1000);
48
  } else resolve(isNSFW)
49
  })
50
  }
51
 
52
  const isNSFW: any = await checkIfIsNSFW(blob)
53
- console.log(isNSFW)
54
 
55
  if (isNSFW?.error) return Response.json({ status: 500, ok: false, message: isNSFW?.error });
56
 
 
41
  const isNSFW = await response_nsfw.clone().json().catch(() => ({}));
42
 
43
  if (isNSFW?.error && isNSFW?.estimated_time) {
 
44
  setTimeout(() => {
45
  checkIfIsNSFW(blob)
46
+ }, isNSFW?.estimated_time * 100);
47
  } else resolve(isNSFW)
48
  })
49
  }
50
 
51
  const isNSFW: any = await checkIfIsNSFW(blob)
 
52
 
53
  if (isNSFW?.error) return Response.json({ status: 500, ok: false, message: isNSFW?.error });
54
 
components/main/collections/index.tsx CHANGED
@@ -29,7 +29,6 @@ export const Collections: React.FC<{ category: string }> = ({ category }) => {
29
  infiniteRefetch();
30
  }}
31
  hasMore={pagination?.total_pages > pagination?.page}
32
- // loader={<p className="bg-red-500 text-white text-2xl">loading...</p>}
33
  className="mx-auto grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-5 mt-8 lg:mt-14"
34
  >
35
  {images?.map((collection: Image, i: number) =>
 
29
  infiniteRefetch();
30
  }}
31
  hasMore={pagination?.total_pages > pagination?.page}
 
32
  className="mx-auto grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-5 mt-8 lg:mt-14"
33
  >
34
  {images?.map((collection: Image, i: number) =>
components/main/hooks/useInputGeneration.ts CHANGED
@@ -2,7 +2,7 @@ import { useId, useState } from "react"
2
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
3
  import { useLocalStorage } from 'react-use';
4
 
5
- import { Collection } from "@/utils/type"
6
  import list_styles from "@/assets/list_styles.json"
7
  import { useCollection } from "@/components/modal/useCollection";
8
 
@@ -29,16 +29,19 @@ export const useInputGeneration = () => {
29
  // generate string random ID
30
  const id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
31
  if (!hasMadeFirstGeneration) setFirstGenerationDone()
32
- client.setQueryData(["collections"], (old) => {
33
- return [{
34
- id,
35
- loading: true,
36
- blob: {
37
- type: "image/png",
38
- data: new ArrayBuffer(0),
39
- },
40
- prompt
41
- }, ...old as Collection[]]
 
 
 
42
  })
43
 
44
  const findStyle = list_styles.find((item) => item.name === style)
@@ -52,16 +55,19 @@ export const useInputGeneration = () => {
52
  })
53
  const data = await response.json()
54
 
55
- client.setQueryData(["collections"], (old) => {
56
- const newArray = [...old as Collection[]]
57
- const index = newArray.findIndex((item: Collection) => item.id === id)
58
 
59
  newArray[index] = !data.ok ? {
60
  ...newArray[index],
61
  error: data.message
62
- } : data?.blob as Collection
63
 
64
- return newArray
 
 
 
65
  })
66
 
67
  if (!data.ok) return null
 
2
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
3
  import { useLocalStorage } from 'react-use';
4
 
5
+ import { Collection, Image } from "@/utils/type"
6
  import list_styles from "@/assets/list_styles.json"
7
  import { useCollection } from "@/components/modal/useCollection";
8
 
 
29
  // generate string random ID
30
  const id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
31
  if (!hasMadeFirstGeneration) setFirstGenerationDone()
32
+ client.setQueryData(["collections"], (old: any) => {
33
+ return {
34
+ pagination: old.pagination,
35
+ images: [{
36
+ id,
37
+ loading: true,
38
+ blob: {
39
+ type: "image/png",
40
+ data: new ArrayBuffer(0),
41
+ },
42
+ prompt
43
+ }, ...old.images as Image[]]
44
+ }
45
  })
46
 
47
  const findStyle = list_styles.find((item) => item.name === style)
 
55
  })
56
  const data = await response.json()
57
 
58
+ client.setQueryData(["collections"], (old: any) => {
59
+ const newArray = [...old?.images as Image[]]
60
+ const index = newArray.findIndex((item: Image) => item.id === id)
61
 
62
  newArray[index] = !data.ok ? {
63
  ...newArray[index],
64
  error: data.message
65
+ } : data?.blob as Image
66
 
67
+ return {
68
+ ...old,
69
+ images:newArray,
70
+ }
71
  })
72
 
73
  if (!data.ok) return null