This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
skynet-webportal/packages/dashboard-v2/src/components/FileList/useSkylinkOptions.js

36 lines
945 B
JavaScript

import { useMemo, useState } from "react";
import accountsService from "../../services/accountsService";
import skynetClient from "../../services/skynetClient";
export const useSkylinkOptions = ({ skylink, onUpdated }) => {
const [inProgress, setInProgress] = useState(false);
const options = useMemo(
() => [
{
label: "Preview",
callback: async () => window.open(await skynetClient.getSkylinkUrl(skylink)),
},
{
label: "Download",
callback: () => skynetClient.downloadFile(skylink),
},
{
label: "Unpin",
callback: async () => {
setInProgress(true);
await accountsService.delete(`user/uploads/${skylink}`);
await onUpdated(); // No need to setInProgress(false), since at this point this hook should already be unmounted
},
},
],
[skylink, onUpdated]
);
return {
inProgress,
options,
};
};