mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Co-authored-by: InfiniteStash <117855276+InfiniteStash@users.noreply.github.com> Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
38 lines
946 B
TypeScript
38 lines
946 B
TypeScript
import { useContext } from "react";
|
|
import { useConfigureUI } from "src/core/StashService";
|
|
import { ConfigurationContext } from "src/hooks/Config";
|
|
import { useToast } from "./Toast";
|
|
|
|
export const useTableColumns = (
|
|
tableName: string,
|
|
defaultColumns: string[]
|
|
) => {
|
|
const Toast = useToast();
|
|
|
|
const { configuration } = useContext(ConfigurationContext);
|
|
const [saveUI] = useConfigureUI();
|
|
|
|
const selectedColumns: string[] =
|
|
configuration?.ui?.tableColumns?.[tableName] ?? defaultColumns;
|
|
|
|
async function saveColumns(updatedColumns: readonly string[]) {
|
|
try {
|
|
await saveUI({
|
|
variables: {
|
|
input: {
|
|
...configuration?.ui,
|
|
tableColumns: {
|
|
...configuration?.ui?.tableColumns,
|
|
[tableName]: updatedColumns,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
} catch (e) {
|
|
Toast.error(e);
|
|
}
|
|
}
|
|
|
|
return { selectedColumns, saveColumns };
|
|
};
|