mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 23:44:22 +00:00
Migrate useFileList
This commit is contained in:
@@ -1,16 +1,22 @@
|
|||||||
import { useState, useCallback } from 'react';
|
import { useState, useCallback } from 'react';
|
||||||
import { fetchFileList } from '../api/git';
|
import { listFiles } from '../api/file';
|
||||||
import { useWorkspace } from '../contexts/WorkspaceContext';
|
import { useWorkspace } from '../contexts/WorkspaceContext';
|
||||||
|
import { FileNode } from '../types/fileApi';
|
||||||
|
|
||||||
export const useFileList = () => {
|
interface UseFileListResult {
|
||||||
const [files, setFiles] = useState([]);
|
files: FileNode[];
|
||||||
|
loadFileList: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useFileList = (): UseFileListResult => {
|
||||||
|
const [files, setFiles] = useState<FileNode[]>([]);
|
||||||
const { currentWorkspace, loading: workspaceLoading } = useWorkspace();
|
const { currentWorkspace, loading: workspaceLoading } = useWorkspace();
|
||||||
|
|
||||||
const loadFileList = useCallback(async () => {
|
const loadFileList = useCallback(async (): Promise<void> => {
|
||||||
if (!currentWorkspace || workspaceLoading) return;
|
if (!currentWorkspace || workspaceLoading) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fileList = await fetchFileList(currentWorkspace.name);
|
const fileList = await listFiles(currentWorkspace.name);
|
||||||
if (Array.isArray(fileList)) {
|
if (Array.isArray(fileList)) {
|
||||||
setFiles(fileList);
|
setFiles(fileList);
|
||||||
} else {
|
} else {
|
||||||
Reference in New Issue
Block a user