DeathDaDev commited on
Commit
e303d00
1 Parent(s): 05ac421

fix: Correct SpaceBrowser component structure and remove outdated random space fetching logic

Browse files
components/shuffler/index.tsx CHANGED
@@ -1,9 +1,9 @@
1
  "use client";
2
 
3
- import { useState } from "react";
4
  import { motion, AnimatePresence } from "framer-motion";
5
 
6
- import { getSpace } from "@/app/actions";
7
  import { Space as SpaceProps } from "@/utils/types";
8
  import { Space } from "@/components/space";
9
 
@@ -47,45 +47,4 @@ export const SpaceBrowser = ({
47
  </footer>
48
  </motion.div>
49
  );
50
- };
51
- space: initialSpace,
52
- nextSpace: initialNextSpace,
53
- }: {
54
- space: SpaceProps;
55
- nextSpace: SpaceProps;
56
- }) => {
57
- const [index, setIndex] = useState(0);
58
- const [space, setSpace] = useState<SpaceProps>(
59
- JSON.parse(JSON.stringify(initialSpace))
60
- );
61
- const [nextSpace, setNextSpace] = useState<SpaceProps>(
62
- JSON.parse(JSON.stringify(initialNextSpace))
63
- );
64
-
65
- return (
66
- <motion.div className="grid grid-cols-1 gap-10 relative">
67
- <div className="relative w-full h-[290px] lg:h-[350px]">
68
- <AnimatePresence initial={false}>
69
- <Card key={index + 1} front={false}>
70
- <Space space={nextSpace} />
71
- </Card>
72
- <Card key={index} front={true} index={index} setIndex={setIndex}>
73
- <Space space={space} />
74
- </Card>
75
- </AnimatePresence>
76
- </div>
77
- <div className="w-4 h-[1px] bg-white/50 mx-auto hidden lg:block" />
78
- <footer className="flex items-center justify-center fixed lg:relative bottom-0 left-0 w-full">
79
- <ButtonShuffler
80
- onClick={() => {
81
- getSpace().then((newSpace) => {
82
- setSpace(nextSpace);
83
- setNextSpace(newSpace);
84
- setIndex(index + 1);
85
- });
86
- }}
87
- />
88
- </footer>
89
- </motion.div>
90
- );
91
  };
 
1
  "use client";
2
 
3
+ import { useState, useEffect } from "react";
4
  import { motion, AnimatePresence } from "framer-motion";
5
 
6
+ import { fetchFilteredSpaces } from "@/utils/network";
7
  import { Space as SpaceProps } from "@/utils/types";
8
  import { Space } from "@/components/space";
9
 
 
47
  </footer>
48
  </motion.div>
49
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  };
utils/network.ts CHANGED
@@ -41,22 +41,4 @@ export const fetchFilteredSpaces = async (hardwareType: 'gpu' | 'cpu', searchQue
41
  colorTo: COLORS.to[space.colorTo as keyof typeof COLORS.from] || COLORS.to.pink,
42
  }));
43
  };
44
- const randomPage = Math.floor(Math.random() * 100) + 1;
45
- const url = `https://huggingface.co/spaces-json?p=${randomPage}&runtime.stage=RUNNING&sort=trending`;
46
- const response = await fetch(url);
47
- const json = await response.json();
48
- const spaces = json?.spaces;
49
-
50
- if (!spaces) {
51
- return null;
52
- }
53
-
54
- const randomIndex = Math.floor(Math.random() * spaces.length);
55
-
56
- const space = {
57
- ...spaces[randomIndex],
58
- colorFrom: COLORS.from[spaces[randomIndex].colorFrom as keyof typeof COLORS.from] || COLORS.from.purple,
59
- colorTo: COLORS.to[spaces[randomIndex].colorTo as keyof typeof COLORS.from] || COLORS.to.pink,
60
- }
61
- return space;
62
  }
 
41
  colorTo: COLORS.to[space.colorTo as keyof typeof COLORS.from] || COLORS.to.pink,
42
  }));
43
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
utils/types.ts CHANGED
@@ -24,5 +24,5 @@ export interface SpaceRuntime {
24
  stage: string;
25
  hardware: {
26
  current: string;
27
- }
28
- }
 
24
  stage: string;
25
  hardware: {
26
  current: string;
27
+ };
28
+ }