-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle empty download directory
Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com>
- Loading branch information
Showing
8 changed files
with
150 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
|
||
interface DownloadMessageProps { | ||
hasFiles: boolean; | ||
} | ||
|
||
const DownloadMessage: React.FC<DownloadMessageProps> = ({ hasFiles }) => { | ||
return ( | ||
<p> | ||
{hasFiles ? ( | ||
'This is the list of Anki decks detected from your upload.' | ||
) : ( | ||
<> | ||
No Anki decks found. Learn more about creating valid flashcards at{' '} | ||
<a href="https://docs.2anki.net/">2anki.net documentation</a>. | ||
</> | ||
)} | ||
</p> | ||
); | ||
}; | ||
|
||
export default DownloadMessage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const DownloadFooter = () => { | ||
return ( | ||
<p> | ||
This folder will be automatically deleted. Return to{' '} | ||
<a href="https://2anki.net">2anki.net</a> | ||
</p> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import path from 'path'; | ||
import React from 'react'; | ||
|
||
interface DownloadListProps { | ||
apkgFiles: string[]; | ||
id: string; | ||
styles: { | ||
downloadList: React.CSSProperties; | ||
downloadItem: React.CSSProperties; | ||
downloadItemName: React.CSSProperties; | ||
downloadItemLink: React.CSSProperties; | ||
}; | ||
} | ||
|
||
const DownloadList: React.FC<DownloadListProps> = ({ | ||
apkgFiles, | ||
id, | ||
styles, | ||
}) => { | ||
return ( | ||
<ul style={styles.downloadList}> | ||
{apkgFiles.map((file) => ( | ||
<li key={file} style={styles.downloadItem}> | ||
<span style={styles.downloadItemName}>{file}</span> | ||
<a | ||
style={styles.downloadItemLink} | ||
download={`${path.basename(file)}`} | ||
href={`${id}/${file}`} | ||
> | ||
Download | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
export default DownloadList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface DownloadTitleProps { | ||
hasFiles: boolean; | ||
} | ||
|
||
export const DownloadTitle = ({ hasFiles }: DownloadTitleProps) => { | ||
return hasFiles ? 'Your downloads are ready' : 'No downloads available'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export const styles = { | ||
downloadContainer: { | ||
margin: '0 auto', | ||
maxWidth: '800px', | ||
padding: '20px', | ||
border: '1px solid #ccc', | ||
}, | ||
downloadHeader: { | ||
fontSize: '24px', | ||
marginBottom: '20px', | ||
}, | ||
downloadList: { | ||
listStyle: 'none', | ||
padding: '0', | ||
margin: '0', | ||
}, | ||
downloadItem: { | ||
marginBottom: '10px', | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
}, | ||
downloadItemName: { | ||
display: 'block', | ||
padding: '10px 20px', | ||
backgroundColor: '#eee', | ||
textDecoration: 'none', | ||
color: '#000', | ||
maxWidth: '80%', | ||
overflow: 'hidden', | ||
textOverflow: 'ellipsis', | ||
}, | ||
downloadItemLinkHover: { | ||
backgroundColor: '#ddd', | ||
}, | ||
downloadItemLink: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import ReactDOMServer from 'react-dom/server'; | ||
import { DownloadTitle } from '../components/download/DownloadTitle'; | ||
import DownloadMessage from '../components/download/DownloadDescription'; | ||
import DownloadList from '../components/download/DownloadList'; | ||
import { DownloadFooter } from '../components/download/DownloadFooter'; | ||
import { styles } from '../components/download/styles'; | ||
|
||
interface DownloadPageProps { | ||
id: string; | ||
files: string[]; | ||
} | ||
|
||
export const DownloadPage = ({ id, files }: DownloadPageProps) => { | ||
const apkgFiles = files.filter((file) => file.endsWith('.apkg')); | ||
const hasFiles = apkgFiles.length > 0; | ||
|
||
return ReactDOMServer.renderToStaticMarkup( | ||
<html> | ||
<head> | ||
<title> | ||
<DownloadTitle hasFiles={hasFiles} /> | ||
</title> | ||
</head> | ||
<body style={styles.downloadContainer}> | ||
<header style={{ padding: '1rem' }}> | ||
<h1 style={styles.downloadHeader}> | ||
<DownloadTitle hasFiles={hasFiles} /> | ||
</h1> | ||
<DownloadMessage hasFiles={hasFiles} /> | ||
</header> | ||
<main> | ||
<DownloadList apkgFiles={apkgFiles} id={id} styles={styles} /> | ||
</main> | ||
{hasFiles && <DownloadFooter />} | ||
</body> | ||
</html> | ||
); | ||
}; |