Skip to content

Commit e545191

Browse files
committed
feat(auto_source): enhance UI and improve form handling
1 parent fa12ab8 commit e545191

File tree

4 files changed

+57
-34
lines changed

4 files changed

+57
-34
lines changed

public/auto_source.css

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
flex-direction: column;
55
}
66

7+
.auto_source__wrapper {
8+
display: flex;
9+
flex-direction: column;
10+
margin: 0 0 1em;
11+
background: var(--background-alt);
12+
padding: 0.75em 1em;
13+
border-radius: 1em;
14+
}
715
.auto_source input,
816
.auto_source button {
917
width: 100%;
@@ -14,11 +22,6 @@
1422
flex-direction: column;
1523
}
1624

17-
.auto_source > form input[type="submit"] {
18-
flex: 1 1;
19-
margin-right: 0;
20-
}
21-
2225
.auto_source > form label {
2326
display: flex;
2427
justify-content: center;
@@ -33,22 +36,24 @@
3336
flex: 0;
3437
}
3538

36-
.auto_source > nav {
39+
.auto_source nav {
3740
display: flex;
3841
flex-direction: column;
3942
}
4043

4144
@media screen and (min-width: 768px) {
42-
.auto_source > nav {
45+
.auto_source nav {
4346
justify-content: space-between;
4447
flex-direction: row;
4548
}
4649
}
4750

48-
.auto_source > nav button {
51+
.auto_source nav button {
4952
margin-left: 0.25em;
5053
margin-right: 0;
5154
flex: 1;
55+
font-size: 0.9em;
56+
padding: 0.75em;
5257
}
5358

5459
.auto_source__bookmarklet {
@@ -63,7 +68,7 @@
6368
}
6469

6570
.auto_source iframe {
66-
margin-top: 2em;
71+
margin-top: 1em;
6772
border: 2px groove transparent;
6873
border-radius: 0.5em;
6974
display: none; /* Hide by default */

public/auto_source.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ const autoSource = (function () {
4747
initEventListeners() {
4848
// Event listener for URL input change
4949
this.urlInput.addEventListener("change", () => this.clearRssUrl());
50+
this.urlInput.addEventListener("blur", (event) => this.handleFormSubmit(event));
5051

5152
// Event listener for form submit
5253
this.form.addEventListener("submit", (event) => this.handleFormSubmit(event));
5354

55+
const $radios = this.form?.querySelectorAll('input[type="radio"]');
56+
Array.from($radios).forEach(($radio) => {
57+
$radio.addEventListener("change", (event) => this.handleFormSubmit(event));
58+
});
59+
5460
// Event listener for RSS URL input focus
5561
this.rssUrlInput.addEventListener("focus", () => {
56-
const strippedIframeSrc = this.iframe.src.replace("#items", "").trim();
62+
const strippedIframeSrc = this.iframe.src.trim();
5763
if (this.rssUrlInput.value.trim() !== strippedIframeSrc) {
5864
this.updateIframeSrc(this.rssUrlInput.value.trim());
5965
}
@@ -104,8 +110,9 @@ const autoSource = (function () {
104110
this.rssUrlInput.value = autoSourceUrl;
105111
this.rssUrlInput.select();
106112

107-
if (window.location.search !== `?url=${url}`) {
108-
window.history.pushState({}, "", `?url=${url}`);
113+
const targetSearch = `?url=${url}&strategy=${strategy}`;
114+
if (window.location.search !== targetSearch) {
115+
window.history.pushState({}, "", targetSearch);
109116
}
110117
}
111118
}
@@ -151,7 +158,7 @@ const autoSource = (function () {
151158
* @param {string} rssUrlValue - The RSS URL value.
152159
*/
153160
updateIframeSrc(rssUrlValue) {
154-
this.iframe.src = rssUrlValue === "" ? "" : `${rssUrlValue}#items`;
161+
this.iframe.src = rssUrlValue === "" ? "about://blank" : `${rssUrlValue}`;
155162
}
156163
}
157164

@@ -196,7 +203,7 @@ const autoSource = (function () {
196203
*/
197204
async copyText() {
198205
try {
199-
const textToCopy = this.rssUrlField.value;
206+
const textToCopy = this.rssUrlWithAuth;
200207
await navigator.clipboard.writeText(textToCopy);
201208
} catch (error) {
202209
console.error("Failed to copy text to clipboard:", error);
@@ -207,7 +214,7 @@ const autoSource = (function () {
207214
* Opens the link specified in the text field.
208215
*/
209216
openLink() {
210-
const linkToOpen = this.rssUrlField?.value;
217+
const linkToOpen = this.rssUrlWithAuth;
211218

212219
if (typeof linkToOpen === "string" && linkToOpen.trim() !== "") {
213220
window.open(linkToOpen, "_blank", "noopener,noreferrer");
@@ -218,6 +225,10 @@ const autoSource = (function () {
218225
* Subscribes to the feed specified in the text field.
219226
*/
220227
async subscribeToFeed() {
228+
window.open(this.rssUrlWithAuth);
229+
}
230+
231+
get rssUrlWithAuth() {
221232
const feedUrl = this.rssUrlField.value;
222233
const storedUser = LocalStorageFacade.getOrAsk("username");
223234
const storedPassword = LocalStorageFacade.getOrAsk("password");
@@ -226,9 +237,7 @@ const autoSource = (function () {
226237
url.username = storedUser;
227238
url.password = storedPassword;
228239

229-
const feedUrlWithAuth = `feed:${url.toString()}`;
230-
231-
window.open(feedUrlWithAuth);
240+
return `feed:${url.toString()}`;
232241
}
233242

234243
resetCredentials() {

public/styles.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,20 @@ html {
1919

2020
body {
2121
scroll-behavior: smooth;
22+
margin: 0 auto;
2223
}
2324

2425
/* General Styles */
26+
27+
h1,
28+
h2,
29+
h3,
30+
h4,
31+
h5,
32+
h6 {
33+
margin: 1rem 0;
34+
}
35+
2536
label {
2637
font-weight: bold;
2738
cursor: pointer;

views/auto_source/index.erb

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88

99
<section class="auto_source">
1010
<h1>Auto Source</h1>
11-
<p>
12-
Automatically sources an RSS feed from a website.
13-
</p>
1411

15-
<form>
12+
<form class="auto_source__wrapper">
1613
<input
1714
id="url"
1815
type="url"
@@ -37,21 +34,22 @@
3734
</label>
3835
<% end %>
3936
</fieldset>
40-
<input type="submit" value="Generate">
4137
</form>
4238

43-
<label>
44-
<img src="/feed.svg" height="16" width="16" alt="the orange RSS icon" role="presentation"/>
45-
Feed URL
46-
<input type="url" id="rss_url" readonly>
47-
</label>
39+
<section class="auto_source__wrapper">
40+
<label>
41+
<img src="/feed.svg" height="16" width="16" alt="the orange RSS icon" role="presentation"/>
42+
Feed URL
43+
<input type="url" id="rss_url" readonly>
44+
</label>
4845

49-
<nav>
50-
<button id="resetCredentials" class="muted">Remove credentials</button>
51-
<button id="copy">Copy URL</button>
52-
<button id="goto">Open</button>
53-
<button id="openInFeed">Subscribe</button>
54-
</nav>
46+
<nav>
47+
<button id="resetCredentials" class="muted">Remove credentials</button>
48+
<button id="copy">Copy URL</button>
49+
<button id="goto">Open</button>
50+
<button id="openInFeed">Subscribe</button>
51+
</nav>
52+
</section>
5553

5654
<iframe loading="lazy"></iframe>
5755
</section>

0 commit comments

Comments
 (0)