mirror of
https://github.com/chinchang/web-maker.git
synced 2025-06-12 04:31:35 +02:00
improve assets ux
This commit is contained in:
@ -9,6 +9,14 @@ import { LoaderWithText } from './Loader';
|
|||||||
import { Text } from './Text';
|
import { Text } from './Text';
|
||||||
import { Icon } from './Icons';
|
import { Icon } from './Icons';
|
||||||
|
|
||||||
|
function getFileType(url) {
|
||||||
|
// get extension from a url using URL API
|
||||||
|
const ext = new URL(url).pathname.split('.').pop();
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'svg'].includes(ext)) {
|
||||||
|
return 'image';
|
||||||
|
}
|
||||||
|
return ext;
|
||||||
|
}
|
||||||
const Assets = ({ onProBtnClick, onLoginBtnClick }) => {
|
const Assets = ({ onProBtnClick, onLoginBtnClick }) => {
|
||||||
const [files, setFiles] = useState([]);
|
const [files, setFiles] = useState([]);
|
||||||
const [isFetchingFiles, setIsFetchingFiles] = useState(false);
|
const [isFetchingFiles, setIsFetchingFiles] = useState(false);
|
||||||
@ -21,9 +29,9 @@ const Assets = ({ onProBtnClick, onLoginBtnClick }) => {
|
|||||||
const storageRef = firebase.storage().ref(`assets/${window.user?.uid}`);
|
const storageRef = firebase.storage().ref(`assets/${window.user?.uid}`);
|
||||||
|
|
||||||
const uploadFile = file => {
|
const uploadFile = file => {
|
||||||
if (file.size > 300 * 1024) {
|
if (file.size > 1024 * 1024) {
|
||||||
// 5MB limit
|
// 1MB limit
|
||||||
alert('File size must be less than 300KB');
|
alert('File size must be less than 1MB');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +55,7 @@ const Assets = ({ onProBtnClick, onLoginBtnClick }) => {
|
|||||||
// Handle unsuccessful uploads
|
// Handle unsuccessful uploads
|
||||||
setIsUploading(false);
|
setIsUploading(false);
|
||||||
console.error('File upload error:', error);
|
console.error('File upload error:', error);
|
||||||
|
alertsService.add('⚠️ File upload failed');
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
// uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => {
|
// uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => {
|
||||||
@ -78,7 +87,10 @@ const Assets = ({ onProBtnClick, onLoginBtnClick }) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Promise.all(filePromises).then(setFiles);
|
Promise.all(filePromises).then(files => {
|
||||||
|
files.forEach(f => (f.ext = getFileType(f.url)));
|
||||||
|
setFiles(files);
|
||||||
|
});
|
||||||
setIsFetchingFiles(false);
|
setIsFetchingFiles(false);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@ -128,7 +140,6 @@ const Assets = ({ onProBtnClick, onLoginBtnClick }) => {
|
|||||||
|
|
||||||
const handleDrop = e => {
|
const handleDrop = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log('drop');
|
|
||||||
setIsDropTarget(false);
|
setIsDropTarget(false);
|
||||||
|
|
||||||
if (e.dataTransfer.items) {
|
if (e.dataTransfer.items) {
|
||||||
@ -139,7 +150,6 @@ const Assets = ({ onProBtnClick, onLoginBtnClick }) => {
|
|||||||
|
|
||||||
const [lastCopiedFile, setLastCopiedFile] = useState({ name: '', count: 0 });
|
const [lastCopiedFile, setLastCopiedFile] = useState({ name: '', count: 0 });
|
||||||
const copyFileUrl = url => {
|
const copyFileUrl = url => {
|
||||||
console.log(lastCopiedFile, url);
|
|
||||||
let copyContent = url;
|
let copyContent = url;
|
||||||
if (lastCopiedFile.name === url) {
|
if (lastCopiedFile.name === url) {
|
||||||
lastCopiedFile.count = (lastCopiedFile.count + 1) % 3;
|
lastCopiedFile.count = (lastCopiedFile.count + 1) % 3;
|
||||||
@ -300,7 +310,26 @@ const Assets = ({ onProBtnClick, onLoginBtnClick }) => {
|
|||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{/* <a href={file.url} target="_blank" rel="noopener noreferrer"> */}
|
{/* <a href={file.url} target="_blank" rel="noopener noreferrer"> */}
|
||||||
<img src={file.url} />{' '}
|
{file.ext === 'image' ? (
|
||||||
|
<img src={file.url} class="asset-manager__file-image" />
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'relative',
|
||||||
|
display: 'flex'
|
||||||
|
}}
|
||||||
|
class="asset-manager__file-image"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="#ffffff33"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path d="M13,9V3.5L18.5,9M6,2C4.89,2 4,2.89 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2H6Z" />
|
||||||
|
</svg>
|
||||||
|
<span className="asset-manager__file-ext">{file.ext}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div class="asset-manager__file-actions">
|
<div class="asset-manager__file-actions">
|
||||||
<Stack gap={1} fullWidth justify="center">
|
<Stack gap={1} fullWidth justify="center">
|
||||||
<button
|
<button
|
||||||
|
@ -2158,7 +2158,7 @@ while the theme CSS file is loading */
|
|||||||
.asset-manager__file-container--grid {
|
.asset-manager__file-container--grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(7, minmax(90px, 1fr));
|
grid-template-columns: repeat(7, minmax(90px, 1fr));
|
||||||
width: 50rem;
|
max-width: 50rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.asset-manager__file {
|
.asset-manager__file {
|
||||||
@ -2172,16 +2172,28 @@ while the theme CSS file is loading */
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.asset-manager__file img {
|
.asset-manager__file-image {
|
||||||
height: 1.5rem;
|
height: 1.5rem;
|
||||||
aspect-ratio: 1;
|
aspect-ratio: 1;
|
||||||
border-radius: 0.3rem;
|
border-radius: 0.3rem;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
.asset-manager__file--grid img {
|
.asset-manager__file--grid .asset-manager__file-image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
.asset-manager__file-ext {
|
||||||
|
text-transform: uppercase;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
letter-spacing: -1px;
|
||||||
|
font-weight: 800;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.asset-manager__file--grid .asset-manager__file-ext {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
.asset-manager__file-actions {
|
.asset-manager__file-actions {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
Reference in New Issue
Block a user