-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor fetching context for React from ModelAdmin
- Loading branch information
Showing
33 changed files
with
288 additions
and
266 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 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 |
---|---|---|
@@ -1,14 +1,11 @@ | ||
import React, {useContext} from 'react'; | ||
import {FinderSettings} from 'finder/FinderSettings'; | ||
import React from 'react'; | ||
import {FileDetails} from 'finder/FileDetails'; | ||
|
||
|
||
export default function Common(props) { | ||
const settings = useContext(FinderSettings); | ||
|
||
return ( | ||
<FileDetails> | ||
<img src={settings.thumbnail_url} /> | ||
<FileDetails {...props}> | ||
<img src={props.settings.thumbnail_url} /> | ||
</FileDetails> | ||
); | ||
} |
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 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
File renamed without changes.
File renamed without changes.
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,16 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import ArchiveIcon from 'icons/archive.svg'; | ||
|
||
|
||
export default function Audio(props) { | ||
console.log(props); | ||
|
||
function archiveSelectedIcons() { | ||
} | ||
|
||
return ( | ||
<li onClick={() => archiveSelectedIcons()} className={props.numSelectedInodes ? null : "disabled"} data-tooltip-id="django-finder-tooltip" data-tooltip-content={gettext("Create archive from selection")}> | ||
<ArchiveIcon /> | ||
</li> | ||
); | ||
} |
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 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 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,90 @@ | ||
import React, {Fragment, useMemo, useRef} from 'react'; | ||
import DownloadIcon from 'icons/download.svg'; | ||
import FullSizeIcon from 'icons/full-size.svg'; | ||
import UploadIcon from 'icons/upload.svg'; | ||
|
||
|
||
function DownloadFileButton(props) { | ||
const {settings} = props; | ||
|
||
return ( | ||
<a download={settings.filename} href={settings.download_url}> | ||
<DownloadIcon/>{gettext("Download")} | ||
</a> | ||
); | ||
} | ||
|
||
|
||
function ViewOriginalButton(props) { | ||
const {settings} = props; | ||
|
||
function viewOriginal() { | ||
window.open(settings.download_url, '_blank').focus(); | ||
} | ||
|
||
return ( | ||
<button type="button" onClick={viewOriginal}> | ||
<FullSizeIcon/>{gettext("View Original")} | ||
</button> | ||
); | ||
} | ||
|
||
|
||
function ReplaceFileButton(props) { | ||
const {settings} = props; | ||
const inputRef = useRef(null); | ||
|
||
function replaceFile() { | ||
inputRef.current.click(); | ||
} | ||
|
||
function handleFileSelect(event) { | ||
const file = event.target.files[0]; | ||
const promise = new Promise<Response>((resolve, reject) => { | ||
file.resolve = resolve; | ||
file.reject = reject; | ||
}); | ||
props.setUploadFile(file); | ||
promise.then((response) => { | ||
window.location.reload(); | ||
}).catch((error) => { | ||
alert(error); | ||
}).finally( () => { | ||
props.setUploadFile(null); | ||
}); | ||
} | ||
|
||
return (<> | ||
<button type="button" onClick={replaceFile}><UploadIcon/>{gettext("Replace File")}</button> | ||
<input type="file" name="replaceFile" ref={inputRef} accept={settings.file_mime_type} onChange={handleFileSelect} /> | ||
</>); | ||
} | ||
|
||
|
||
export function ControlButtons(props) { | ||
//const settings = useContext(FinderSettings); | ||
const {settings} = props; | ||
|
||
const controlButtons = useMemo(() => { | ||
const buttons: Array<React.JSX.Element> = []; | ||
if (settings.download_file) { | ||
buttons.push(<DownloadFileButton {...props} />); | ||
} | ||
if (settings.view_original) { | ||
buttons.push(<ViewOriginalButton {...props} />); | ||
} | ||
if (settings.replace_file) { | ||
buttons.push(<ReplaceFileButton {...props} />); | ||
} | ||
return buttons; | ||
}, []); | ||
|
||
return ( | ||
<div className="button-group"> | ||
{props.children} | ||
{controlButtons.map((button, index) => | ||
<Fragment key={index}>{button}</Fragment> | ||
)} | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.