Skip to content

Commit

Permalink
fix: fetch all files
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-harris committed Dec 21, 2024
1 parent f95ef2f commit 7f47e8e
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions clients/search-component/src/utils/hooks/file-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,36 @@ const FileContext = createContext<{

export const FileContextProvider = (props: { children: ReactNode }) => {
const [files, setFiles] = useState<Record<string, string>>({});
const [page] = useState(1);
const state = useModalState();

useEffect(() => {
const getFiles = async () => {
const files = state.trieveSDK.trieve.fetch(
"/api/dataset/files/{dataset_id}/{page}",
"get",
{
page: 1,
datasetId: state.props.datasetId,
},
);
const page = 1;
let done = false;
const fileMapResult: Record<string, string> = {};
while (!done) {
const files = await state.trieveSDK.trieve.fetch(
"/api/dataset/files/{dataset_id}/{page}",
"get",
{
page,
datasetId: state.props.datasetId,
},
);

if (files.length) {
files.reduce((acc, file) => {
acc[file.file_name] = file.id;
return acc;
}, fileMapResult);
} else {
done = true;
}
}

setFiles(fileMapResult);
};
getFiles();
void getFiles();
}, []);

return (
Expand Down

0 comments on commit 7f47e8e

Please sign in to comment.