Skip to content

Commit

Permalink
fix: create file field
Browse files Browse the repository at this point in the history
  • Loading branch information
eaguad1337 committed Nov 2, 2023
1 parent b3b96a3 commit 2707029
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ format: ## Format code with Black
coverage: ## Run package tests and upload coverage reports
python -m pytest --cov-report term --cov-report xml --cov=src/collapsar tests
publish: ## Publish package to pypi
npx vite build
python setup.py sdist bdist_wheel
twine upload --skip-existing dist/*
rm -fr build dist .egg src/collapsar.egg-info
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version="0.0.12",
version="0.0.13",
packages=[
"collapsar",
"collapsar.config",
Expand Down
22 changes: 12 additions & 10 deletions src/collapsar/assets/js/components/fields/FileField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,26 @@ export function FileField(props: any) {

return (
<>
{props.value && !replaceImage ? (
{!replaceImage ? (
<div>
<Button
type="button"
variant="secondary"
onClick={() => setReplaceImage(true)}
>
Replace
{props.value ? "Replace" : "Set image"}
</Button>
<img
{props.value && (
<img
className="rounded-md border-2 mt-3 max-w-sm"
src={`/${originalValue}`}
alt=""
/>
/>
)}
</div>
) : (
<>
{props.value && (
{fileInput && (
<div className="flex flex-col gap-3">
<div className="flex gap-3">
<Button
Expand All @@ -67,19 +69,19 @@ export function FileField(props: any) {
</Button>
<Button
type="button"
onClick={(e) => fileInput.current?.click()}
onClick={(e) => fileInput?.current?.click()}
>
{fileInput.current?.files?.length > 0 ? "Change selection" : "Select"}
{fileInput?.current?.files?.length > 0 ? "Change selection" : "Select"}
</Button>
</div>
{fileInput.current?.files?.length > 0 ? (
{fileInput?.current?.files?.length > 0 ? (
<div className="text-sm flex flex-col gap-3">
<div id="filename">
<div className="span">
{fileInput.current.files[0].name}{" "}
{fileInput?.current.files[0].name}{" "}
</div>
<span className="text-muted-foreground">
{(fileInput.current.files[0].size / 1024).toFixed(1)} kb
{(fileInput?.current.files[0].size / 1024).toFixed(1)} kb
</span>
</div>
<img
Expand Down

0 comments on commit 2707029

Please sign in to comment.