Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 9, 2024
1 parent 8c7797b commit 385caa1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 64 deletions.
86 changes: 49 additions & 37 deletions solara/lib/core/dashboard/brand/BrandController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,63 @@ class BrandController {

async initRemote() {
this.view.uploadJsonBtn.addEventListener('click', async () => {
try {
const [fileHandle] = await window.showOpenFilePicker({
types: [{
description: 'JSON File',
accept: {
'application/json': ['.json'],
},
}],
});

const file = await fileHandle.getFile();

const json = await this.model.getBrandConfigurationsJsonFromDirectory(file);

if (!json) {
alert("The selected JSON file is not a valid configuration for Solara brands.");
return
}
await this.addBrand(json.brand.key, json.brand.name, json.configurations)
} catch (error) {
console.error('Error:', error);
}
await this.uploadJson()
});

this.view.uploadBrandBtn.addEventListener('click', async () => {
try {
const dirHandle = await window.showDirectoryPicker();
const configurations = await this.model.createBrandConfigurationsFromDirectory(dirHandle);

this.view.showOnboardBrandForm((key, name) => {
this.addBrand(key, name, configurations)
})
} catch (error) {
console.error('Error:', error);
}
await this.uploadBrand()
});
this.view.addNewBrandBtn.addEventListener('click', async () => {
this.view.showOnboardBrandForm(async (key, name) => {
const configurations = await this.model.createNewBrandConfogurations()
console.log(configurations)
await this.addBrand(key, name, configurations)
})
await this.addNewBrand()
});
}

async uploadJson() {
try {
const [fileHandle] = await window.showOpenFilePicker({
types: [{
description: 'JSON File',
accept: {
'application/json': ['.json'],
},
}],
});

const file = await fileHandle.getFile();

const json = await this.model.getBrandConfigurationsJsonFromDirectory(file);

if (!json) {
alert("The selected JSON file is not a valid configuration for Solara brands.");
return
}
await this.addBrand(json.brand.key, json.brand.name, json.configurations)
} catch (error) {
console.error('Error:', error);
}
}

async uploadBrand() {
try {
const dirHandle = await window.showDirectoryPicker();
const configurations = await this.model.createBrandConfigurationsFromDirectory(dirHandle);

this.view.showOnboardBrandForm((key, name) => {
this.addBrand(key, name, configurations)
})
} catch (error) {
console.error('Error:', error);
}
}

async addNewBrand() {
this.view.showOnboardBrandForm(async (key, name) => {
const configurations = await this.model.createNewBrandConfogurations()
console.log(configurations)
await this.addBrand(key, name, configurations)
})
}

async addBrand(key, name, configurations) {
const result = {
brand: {key: key, name: name},
Expand Down
12 changes: 1 addition & 11 deletions solara/lib/core/dashboard/brand/brand.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,6 @@
margin-bottom: 32px;
}

.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
}
@media (max-width: 768px) {
.container {
padding: 10px;
Expand Down Expand Up @@ -347,7 +337,7 @@
padding: 40px;
border-radius: 20px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
z-index: 1000;
z-index: 999;
animation: fadeIn 0.5s ease-out;
}

Expand Down
10 changes: 0 additions & 10 deletions solara/lib/core/dashboard/brands/brands.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@
margin-bottom: 20px;
text-align: center;
}
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
}
.brands-list-header {
display: flex;
justify-content: space-between;
Expand Down
7 changes: 4 additions & 3 deletions solara/lib/core/dashboard/component/AddFieldSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class AddFieldSheet extends HTMLElement {
this.onSubmit = null;
this.inputType = null;

this.attachShadow({ mode: 'open' });
this.attachShadow({mode: 'open'});
this.render();

this.addFieldSheet = this.shadowRoot.querySelector('#addFieldSheet');
this.overlay = this.shadowRoot.querySelector('.overlay');
this.overlay = this.shadowRoot.getElementById('overlay');

this.shadowRoot.querySelector('#addFieldForm').onsubmit = (e) => this.handleSubmit(e);
this.shadowRoot.querySelector('#colorPicker').oninput = (e) => this.updateFieldValue(e);
Expand Down Expand Up @@ -53,6 +53,7 @@ class AddFieldSheet extends HTMLElement {
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 999;
}
.show {
display: block;
Expand Down Expand Up @@ -142,7 +143,7 @@ class AddFieldSheet extends HTMLElement {
border-radius: 4px; /* Optional: Rounded corners */
}
</style>
<div class="overlay"></div>
<div id="overlay" class="overlay"></div>
<div class="bottom-sheet" id="addFieldSheet">
<h3>Add New Field</h3>
<form id="addFieldForm">
Expand Down
2 changes: 1 addition & 1 deletion solara/lib/core/dashboard/component/ConfirmationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ConfirmationDialog extends HTMLElement {
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
z-index: 999;
}
</style>
<div class="overlay" id="overlay"></div>
Expand Down
4 changes: 2 additions & 2 deletions solara/lib/core/dashboard/component/MessageBottomSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class MessageBottomSheet extends HTMLElement {
<div class="message-content" id="messageContent"></div>
<button class="close-message" id="closeMessage">Close</button>
</div>
<div class="overlay" style="display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); z-index: 999;"></div>
<div id="overlay" class="overlay" style="display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); z-index: 999;"></div>
`;

this.messageBottomSheet = this.shadowRoot.getElementById('messageBottomSheet');
this.messageContent = this.shadowRoot.getElementById('messageContent');
this.closeMessageButton = this.shadowRoot.getElementById('closeMessage');
this.overlay = this.shadowRoot.querySelector('.overlay');
this.overlay = this.shadowRoot.getElementById('overlay');

this.closeMessageButton.onclick = () => this.hideMessage();
this.overlay.onclick = () => this.hideMessage();
Expand Down

0 comments on commit 385caa1

Please sign in to comment.