Skip to content

Commit fb16931

Browse files
committed
feat: download images in phoenix code assets folder
1 parent a9c7bd6 commit fb16931

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,23 +2134,6 @@ function RemoteFunctions(config = {}) {
21342134
transition: all 0.2s ease !important;
21352135
}
21362136
2137-
.phoenix-ribbon-folder-select {
2138-
background: rgba(0,0,0,0.5) !important;
2139-
border: none !important;
2140-
color: white !important;
2141-
cursor: pointer !important;
2142-
padding: 4px 8px !important;
2143-
border-radius: 3px !important;
2144-
margin-right: 8px !important;
2145-
display: flex !important;
2146-
align-items: center !important;
2147-
justify-content: center !important;
2148-
}
2149-
2150-
.phoenix-ribbon-folder-select:hover {
2151-
background: rgba(0,0,0,0.7) !important;
2152-
}
2153-
21542137
.phoenix-ribbon-close {
21552138
background: rgba(0,0,0,0.5) !important;
21562139
border: none !important;
@@ -2267,11 +2250,6 @@ function RemoteFunctions(config = {}) {
22672250
</div>
22682251
</div>
22692252
<div class="phoenix-ribbon-header-right">
2270-
<button class="phoenix-ribbon-folder-select" title="${config.strings.imageGalleryChooseFolder}">
2271-
<svg viewBox="0 0 24 24" fill="currentColor" width="20" height="20">
2272-
<path d="M10 4H4c-1.11 0-2 .89-2 2v12c0 1.11.89 2 2 2h16c1.11 0 2-.89 2-2V8c0-1.11-.89-2-2-2h-8l-2-2z"/>
2273-
</svg>
2274-
</button>
22752253
<button class="phoenix-ribbon-close">×</button>
22762254
</div>
22772255
</div>
@@ -2551,7 +2529,6 @@ function RemoteFunctions(config = {}) {
25512529
const searchInput = this._shadow.querySelector('.phoenix-ribbon-search input');
25522530
const searchButton = this._shadow.querySelector('.phoenix-ribbon-search-btn');
25532531
const closeButton = this._shadow.querySelector('.phoenix-ribbon-close');
2554-
const folderSelectBtn = this._shadow.querySelector('.phoenix-ribbon-folder-select');
25552532
const navLeft = this._shadow.querySelector('.phoenix-ribbon-nav.left');
25562533
const navRight = this._shadow.querySelector('.phoenix-ribbon-nav.right');
25572534
const selectImageBtn = this._shadow.querySelector('.phoenix-select-image-btn');
@@ -2605,13 +2582,6 @@ function RemoteFunctions(config = {}) {
26052582
});
26062583
}
26072584

2608-
if (folderSelectBtn) {
2609-
folderSelectBtn.addEventListener('click', (e) => {
2610-
e.stopPropagation();
2611-
console.log('i got clicked');
2612-
});
2613-
}
2614-
26152585
if (navLeft) {
26162586
navLeft.addEventListener('click', (e) => {
26172587
e.stopPropagation();

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,12 +755,39 @@ define(function (require, exports, module) {
755755
const projectRoot = ProjectManager.getProjectRoot();
756756
if (!projectRoot) { return; }
757757

758-
getUniqueFilename(projectRoot.fullPath, filename, extnName).then((uniqueFilename) => {
758+
// phoenix-assets folder, all the images will be stored inside this
759+
const phoenixAssetsPath = projectRoot.fullPath + "phoenix-code-assets/";
760+
const phoenixAssetsDir = FileSystem.getDirectoryForPath(phoenixAssetsPath);
761+
762+
// check if the phoenix-assets dir exists
763+
// if present, download the image inside it, if not create the dir and then download the image inside it
764+
phoenixAssetsDir.exists((err, exists) => {
765+
if (err) { return; }
766+
767+
if (!exists) {
768+
phoenixAssetsDir.create((err) => {
769+
if (err) {
770+
console.error('Error creating phoenix-code-assets directory:', err);
771+
return;
772+
}
773+
_downloadImageToPhoenixAssets(message, filename, extnName, phoenixAssetsDir);
774+
});
775+
} else {
776+
_downloadImageToPhoenixAssets(message, filename, extnName, phoenixAssetsDir);
777+
}
778+
});
779+
}
780+
781+
/**
782+
* Helper function to download image to phoenix-assets folder
783+
*/
784+
function _downloadImageToPhoenixAssets(message, filename, extnName, phoenixAssetsDir) {
785+
getUniqueFilename(phoenixAssetsDir.fullPath, filename, extnName).then((uniqueFilename) => {
759786
// check if the image is loaded from computer or from remote
760787
if (message.isLocalFile && message.imageData) {
761-
_handleUseThisImageLocalFiles(message, uniqueFilename, projectRoot);
788+
_handleUseThisImageLocalFiles(message, uniqueFilename, phoenixAssetsDir);
762789
} else {
763-
_handleUseThisImageRemote(message, uniqueFilename, projectRoot);
790+
_handleUseThisImageRemote(message, uniqueFilename, phoenixAssetsDir);
764791
}
765792
}).catch(error => {
766793
console.error('Something went wrong when trying to use this image', error);

0 commit comments

Comments
 (0)