Skip to content

Commit

Permalink
Merge pull request #2 from ocni-dtu/chrk/download_button
Browse files Browse the repository at this point in the history
added download button
  • Loading branch information
ocni-dtu authored Jan 24, 2024
2 parents 5b372c2 + edfb555 commit 61ae41c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @ocni-dtu
12 changes: 11 additions & 1 deletion .github/workflows/deploy-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
pull_request:
branches:
- main

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down Expand Up @@ -39,6 +42,9 @@ jobs:
- name: NPM Install
run: npm ci

- name: Check
run: npm run check

- name: Build
run: npm run build
env:
Expand All @@ -47,13 +53,15 @@ jobs:
VITE_GITHUB_REPO: ${{ vars.VITE_GITHUB_REPO }}

- name: Upload artifact for deployment job
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v3
with:
name: node-app
path: ./dist

deploy:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build
environment:
name: github-pages
Expand All @@ -63,13 +71,15 @@ jobs:
uses: actions/download-artifact@v3
with:
name: node-app

- name: Setup Pages
uses: actions/configure-pages@v3

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload entire repository
path: '.'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"lint:fix": "eslint --fix src/**/*.{tsx,ts}",
"format": "prettier --check \"**/*.{ts,tsx}\"",
"format:fix": "prettier --write \"**/*.{ts,tsx}\"",
"tsc": "tsc --noEmit",
"check": "npm run format && npm run lint && npm run tsc",
"fix": "npm run lint:fix && npm run format:fix"
},
"dependencies": {
Expand Down
23 changes: 22 additions & 1 deletion src/components/searchElement/searchElement.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from '@tanstack/react-query'
import React, { Dispatch, SetStateAction, useMemo, useState } from 'react'
import { ActionIcon, Card, Grid, Tooltip } from '@mantine/core'
import { IconChartBar, IconMinus, IconPlus } from '@tabler/icons-react'
import { IconChartBar, IconDownload, IconMinus, IconPlus } from '@tabler/icons-react'
import { getGitHubFile, SearchItem } from '../../queries'
import { SearchElementTitle } from '../searchElementTitle'
import { SearchElementField } from '../searchElementField'
Expand Down Expand Up @@ -45,6 +45,17 @@ export const SearchElement = ({
}
}

const handleDownloadClick = () => {
const base64doc = btoa(JSON.stringify(data, undefined, 2))
const a = document.createElement('a')
const e = new MouseEvent('click')

a.download = `${data.name}.json`
a.href = 'data:text/json;base64,' + base64doc
a.dispatchEvent(e)
window.umami.track(`Download EPD Button - ${data.name} - ${data.id}`)
}

const gwpData = useMemo(() => {
if (!data) {
return []
Expand Down Expand Up @@ -100,6 +111,16 @@ export const SearchElement = ({
{expanded ? <IconMinus size='1.1rem' /> : <IconPlus size='1.1rem' />}
</Tooltip>
</ActionIcon>
<ActionIcon
variant='default'
style={{ float: 'right' }}
sx={{ marginRight: 5 }}
onClick={handleDownloadClick}
>
<Tooltip label='Download EPD'>
<IconDownload size='1.1rem' />
</Tooltip>
</ActionIcon>
<ActionIcon
variant='default'
style={{ float: 'right' }}
Expand Down
8 changes: 8 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
</BrowserRouter>
</React.StrictMode>,
)

declare global {
interface Window {
umami: {
track: (text: string) => void
}
}
}

0 comments on commit 61ae41c

Please sign in to comment.