Skip to content

Commit

Permalink
Fixed download
Browse files Browse the repository at this point in the history
  • Loading branch information
AmazingBrandonL committed Apr 9, 2024
1 parent b54ef9f commit e9be54b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/webPages/mechanisms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import TaskSharpIcon from '@mui/icons-material/TaskSharp';
import "./mechanisms.css";
import { createMechanism } from '../API/API_CreateMethods';
import { useRef } from 'react';
import { downloadOA } from '../API/API_DeleteMethods';


const MechanismPage = () => {
Expand Down Expand Up @@ -62,7 +63,22 @@ const MechanismPage = () => {
setCreateMechanismOpen(false);
}

const handleDownlaodClick = async () => {
const link = document.createElement("a");
const body = await downloadOA(tagMechanismUuid as string);

const blob = new Blob([body], { type: 'application/json' });

const blobUrl = window.URL.createObjectURL(blob);

link.download = 'openAtmos.json';
link.href = blobUrl;

link.click();

window.URL.revokeObjectURL(blobUrl);
};

var listName = "Options for ";
if(tagMechanismUuid){
listName += getTagMechanism(tagMechanismUuid as string);
Expand Down Expand Up @@ -205,6 +221,15 @@ const MechanismPage = () => {
</ListItemText>
</ListItemButton>
</ListItem>
<ListItem>
<ListItemButton onClick={handleDownlaodClick}>
<ListItemIcon>
<HistoryEduSharpIcon></HistoryEduSharpIcon>
</ListItemIcon>
<ListItemText primary="Downlaod">
</ListItemText>
</ListItemButton>
</ListItem>
</List>
</Box>
</Modal>
Expand Down

0 comments on commit e9be54b

Please sign in to comment.