feat: brand-new interface

This was initally generated by ai, but later has been heavily edited.
The reason why it has been implemented is that there are plans to
implement more features to ui, but it becomes hard to add new features
to plain js, so I decided to rewrite it in typescript.

Yet because it is still ai slop, it is still possible to enable old
interface via configuration, even though new interface is turned on by
default to get feedback
This commit is contained in:
2026-02-25 22:49:38 +02:00
parent db46147f0d
commit dd31f37c2a
158 changed files with 5979 additions and 304 deletions

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2021-2026 ahriman team.
*
* This file is part of ahriman
* (see https://github.com/arcan1s/ahriman).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { useQueryClient } from "@tanstack/react-query";
import { ApiError } from "api/client/ApiError";
import { QueryKeys } from "hooks/QueryKeys";
import { useClient } from "hooks/useClient";
import { useNotification } from "hooks/useNotification";
import { useRepository } from "hooks/useRepository";
export interface UsePackageActionsResult {
handleReload: () => void;
handleUpdate: () => Promise<void>;
handleRefreshDb: () => Promise<void>;
handleRemove: () => Promise<void>;
}
export function usePackageActions(
selectionModel: string[],
setSelectionModel: (model: string[]) => void,
): UsePackageActionsResult {
const client = useClient();
const { current } = useRepository();
const { showSuccess, showError } = useNotification();
const queryClient = useQueryClient();
const handleReload: () => void = () => {
if (!current) {
return;
}
void queryClient.invalidateQueries({ queryKey: QueryKeys.packages(current) });
void queryClient.invalidateQueries({ queryKey: QueryKeys.status(current) });
};
const handleUpdate: () => Promise<void> = async () => {
if (!current) {
return;
}
try {
if (selectionModel.length === 0) {
await client.servicePackageUpdate(current, { packages: [] });
showSuccess("Success", "Repository update has been run");
} else {
await client.servicePackageAdd(current, { packages: selectionModel });
showSuccess("Success", `Run update for packages ${selectionModel.join(", ")}`);
}
setSelectionModel([]);
void queryClient.invalidateQueries({ queryKey: QueryKeys.packages(current) });
void queryClient.invalidateQueries({ queryKey: QueryKeys.status(current) });
} catch (exception) {
const detail = ApiError.errorDetail(exception);
showError("Action failed", `Packages update failed: ${detail}`);
}
};
const handleRefreshDb: () => Promise<void> = async () => {
if (!current) {
return;
}
try {
await client.servicePackageUpdate(current, {
packages: [],
refresh: true,
aur: false,
local: false,
manual: false,
});
showSuccess("Success", "Pacman database update has been requested");
setSelectionModel([]);
void queryClient.invalidateQueries({ queryKey: QueryKeys.packages(current) });
void queryClient.invalidateQueries({ queryKey: QueryKeys.status(current) });
} catch (exception) {
const detail = ApiError.errorDetail(exception);
showError("Action failed", `Could not update pacman databases: ${detail}`);
}
};
const handleRemove: () => Promise<void> = async () => {
if (!current) {
return;
}
if (selectionModel.length === 0) {
return;
}
try {
await client.servicePackageRemove(current, selectionModel);
showSuccess("Success", `Packages ${selectionModel.join(", ")} have been removed`);
setSelectionModel([]);
void queryClient.invalidateQueries({ queryKey: QueryKeys.packages(current) });
void queryClient.invalidateQueries({ queryKey: QueryKeys.status(current) });
} catch (exception) {
const detail = ApiError.errorDetail(exception);
showError("Action failed", `Could not remove packages: ${detail}`);
}
};
return {
handleReload,
handleUpdate,
handleRefreshDb,
handleRemove,
};
}