Skip to content

Commit

Permalink
Merge pull request #7 from razeghi71/improve/search-modal-becomes-form
Browse files Browse the repository at this point in the history
Make QueryModal a form and widen the search input
  • Loading branch information
razeghi71 authored Apr 25, 2024
2 parents 774253f + 05e25d7 commit 256fd5c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "image-search",
"name": "Image Search",
"version": "0.0.4",
"version": "0.0.5",
"minAppVersion": "1.5.12",
"description": "Search and insert images using Google API",
"author": "Mohammad Razeghi",
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-image-search",
"version": "0.0.4",
"version": "0.0.5",
"description": "This is image search plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand Down
39 changes: 29 additions & 10 deletions query-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,44 @@ export class QueryModal extends Modal {
}

onOpen() {
this.contentEl.createEl("h1", { text: "What do you want to search for?" });
const form = this.contentEl.createEl('form');
form.addEventListener('submit', (event) => {
event.preventDefault();
this.search();
});

new Setting(this.contentEl)
.setName("What are you looking for?")
.addText(text => text.onChange(value => this.result = value));
const input = this.contentEl.createEl('input', {
attr: {
type: 'text',
placeholder: "What are you looking for?"
},
cls: 'setting-input input-style',
});
input.addEventListener('input', (event) => {
this.result = (event.target as HTMLInputElement).value;
});
form.appendChild(input);

new Setting(this.contentEl)
.addButton(btn => btn
.setButtonText("Search")
.setCta()
.onClick(() => this.search()));
const buttonContainer = this.contentEl.createEl('div', {
cls: 'button-container-style'
});
const button = this.contentEl.createEl('button', {
attr: {
type: 'submit'
},
cls: 'mod-cta setting-btn button-style',
});
button.textContent = "Search Google Images";
buttonContainer.appendChild(button);
form.appendChild(buttonContainer);

this.imageList = this.contentEl.createEl("ul", { cls: "responsive-gallery" });
}

private async callApi(query: string): Promise<string[]> {
const url = `https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(query)}&cx=${this.settings.searchEngineId}&searchType=image&num=10&key=${this.settings.apiKey}`;
const response = await requestUrl(url);

if (response.status < 200 || response.status >= 300) {
throw new Error(`HTTP error! status: ${response.status}`);
}
Expand Down
16 changes: 16 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,20 @@ ul.responsive-gallery img {
ul.responsive-gallery li {
width: calc(100% / 4); /* 4 images per row */
}
}

/* Additional styles for input and button alignment */
.input-style {
width: 100%;
margin-top: 25px;
margin-bottom: 25px;
}

.button-container-style {
text-align: center;
width: 100%;
}

.button-style {
margin: auto;
}
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"0.0.1": "1.5.12",
"0.0.2": "1.5.12",
"0.0.3": "1.5.12",
"0.0.4": "1.5.12"
"0.0.4": "1.5.12",
"0.0.5": "1.5.12"
}

0 comments on commit 256fd5c

Please sign in to comment.