Skip to content

Commit 99292a3

Browse files
committed
Refactor model download handling in RecommendedModels components
- Simplified the `startDownload` function signature in `RecommendedModels` and `RecommendedModelsDialog` components to accept a single `UnifiedModel` object, enhancing clarity and reducing parameter complexity. - Updated the `ModelRecommendationsButton` to utilize the new `startDownload` implementation, improving the download initiation process. - Cleaned up related code to ensure consistency and maintainability across model recommendation components.
1 parent 23dcf01 commit 99292a3

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

web/src/components/hugging_face/RecommendedModels.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ import { openInExplorer } from "../../utils/fileExplorer";
1818

1919
interface RecommendedModelsProps {
2020
recommendedModels: UnifiedModel[];
21-
startDownload: (
22-
repoId: string,
23-
modelType: string,
24-
path: string | null,
25-
allowPatterns: string[] | null,
26-
ignorePatterns: string[] | null
27-
) => void;
21+
startDownload: (model: UnifiedModel) => void;
2822
}
2923

3024
const RecommendedModels: React.FC<RecommendedModelsProps> = ({
@@ -113,15 +107,7 @@ const RecommendedModels: React.FC<RecommendedModelsProps> = ({
113107
compactView={true}
114108
key={model.id}
115109
model={model}
116-
onDownload={() =>
117-
startDownload(
118-
model.repo_id || "",
119-
model.type || "hf.model",
120-
model.path ?? null,
121-
model.allow_patterns ?? null,
122-
model.ignore_patterns ?? null
123-
)
124-
}
110+
onDownload={() => startDownload(model)}
125111
/>
126112
);
127113
})}

web/src/components/hugging_face/RecommendedModelsDialog.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,7 @@ interface RecommendedModelsDialogProps {
5353
open: boolean;
5454
onClose: () => void;
5555
recommendedModels: UnifiedModel[];
56-
startDownload: (
57-
repoId: string,
58-
modelType: string,
59-
path: string | null,
60-
allowPatterns: string[] | null,
61-
ignorePatterns: string[] | null
62-
) => void;
56+
startDownload: (model: UnifiedModel) => void;
6357
}
6458

6559
const RecommendedModelsDialog: React.FC<RecommendedModelsDialogProps> = ({

web/src/components/node/ModelRecommendationsButton.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@ const ModelRecommendationsButton: React.FC<ModelRecommendationsButtonProps> = ({
1515
recommendedModels
1616
}) => {
1717
const [openModelDialog, setOpenModelDialog] = useState(false);
18-
const { startDownload } = useModelDownloadStore();
18+
const { startDownload, openDialog } = useModelDownloadStore();
1919
const handleOpenModelDialog = useCallback(() => setOpenModelDialog(true), []);
2020
const handleCloseModelDialog = useCallback(
2121
() => setOpenModelDialog(false),
2222
[]
2323
);
2424

25+
const onStartDownload = React.useCallback(
26+
(model: UnifiedModel) => {
27+
const repoId = model.repo_id || model.id;
28+
startDownload(repoId, model.type ?? "", model.path ?? undefined);
29+
openDialog();
30+
},
31+
[startDownload, openDialog]
32+
);
33+
2534
if (recommendedModels.length === 0) {
2635
return null;
2736
}
@@ -65,7 +74,7 @@ const ModelRecommendationsButton: React.FC<ModelRecommendationsButtonProps> = ({
6574
open={openModelDialog}
6675
onClose={handleCloseModelDialog}
6776
recommendedModels={recommendedModels}
68-
startDownload={startDownload}
77+
startDownload={onStartDownload}
6978
/>
7079
</>
7180
);

web/src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ const root = ReactDOM.createRoot(
280280

281281
const AppWrapper = () => {
282282
const [status, setStatus] = useState<string>("pending");
283-
const { state } = useAuth();
284283

285284
useEffect(() => {
286285
// Existing effect for loading metadata

0 commit comments

Comments
 (0)