Skip to content

Commit f89e847

Browse files
authored
support starting with no URL (#32)
if no URL provided in hashtag: - show empty div with modal Create New Archive - don't show linky yet - disallow closing until URL is entered also: - show warning about archive being removed when showing dialog from Restart - tweak Browsertrix text
1 parent f2422ec commit f89e847

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

src/archive-now.ts

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ class ArchiveNow extends LitElement {
7979
private currUrl = "";
8080
private shownForUrl = false;
8181

82+
@state()
83+
private isEmpty = false;
84+
85+
constructor() {
86+
super();
87+
const hash = window.location.hash.startsWith("#url=");
88+
if (!hash) {
89+
this.showHint = false;
90+
this.showCreateDialog = true;
91+
this.isEmpty = true;
92+
this.removeLinky();
93+
}
94+
}
95+
8296
private hintMessages: Record<Hint, TemplateResult> = {
8397
"first-load": html`<p class="mb-3">
8498
Browse and interact with the website like you would normally. Every link
@@ -341,15 +355,16 @@ class ArchiveNow extends LitElement {
341355
? "shadow shadow-earth-800/10 ring-1 ring-earth-300/50"
342356
: "shadow-lg shadow-cyan-800/10 ring-2 ring-cyan-300/50"} overflow-hidden rounded-lg bg-white transition-all [grid-area:archive]"
343357
>
344-
${!this.isFinished
358+
${!this.isEmpty ?
359+
!this.isFinished
345360
? html` <archive-web-page
346361
proxyPrefix="https://archive-now.webrecorder.workers.dev/proxy/"
347362
sandbox="true"
348363
coll=${this.collId}
349364
deepLink="true"
350-
url=${DEFAULT_URL}
351365
></archive-web-page>`
352-
: html` <replay-web-page coll=${this.collId}></replay-web-page>`}
366+
: html` <replay-web-page coll=${this.collId}></replay-web-page>`
367+
: html``}
353368
</div>
354369
<div
355370
class="-mb-4 -mt-4 overflow-auto pb-4 pt-4 [grid-area:detail] lg:mr-0 lg:px-4 2xl:px-6"
@@ -360,7 +375,8 @@ class ArchiveNow extends LitElement {
360375
? "translate-x-0"
361376
: "lg:-translate-x-4"} inline-flex h-8 items-center gap-1.5 rounded-full text-brand-green transition-transform"
362377
>
363-
${this.isFinished
378+
${!this.isEmpty ?
379+
this.isFinished
364380
? html`
365381
🎉
366382
<span class="text-sm"> Archiving finished! </span>
@@ -374,7 +390,7 @@ class ArchiveNow extends LitElement {
374390
Click <strong class="font-semibold">Finish</strong> to
375391
finalize your archive
376392
</span>
377-
`}
393+
` : ``}
378394
</div>
379395
</div>
380396
<!-- FOR LINKY
@@ -391,7 +407,7 @@ class ArchiveNow extends LitElement {
391407
<div
392408
class="pointer-events-none absolute bottom-0 right-0 size-32 opacity-50 transition-opacity delay-75 [background:radial-gradient(farthest-side_at_bottom_right,white,transparent)]"
393409
></div>
394-
${this.renderLinky()} ${this.renderUrlDialog()}
410+
${!this.isEmpty ? this.renderLinky() : ""} ${this.renderUrlDialog()}
395411
`;
396412
}
397413

@@ -487,7 +503,7 @@ class ArchiveNow extends LitElement {
487503
"Browsertrix",
488504
html`
489505
<p>
490-
Fully automated archiving of entire websites on a set schedule.
506+
Automated browser-based crawling at scale.
491507
</p>
492508
`,
493509
{
@@ -635,12 +651,19 @@ class ArchiveNow extends LitElement {
635651
`;
636652
}
637653

654+
private onUrlDialogRequestClose(event: Event) {
655+
if (this.isEmpty) {
656+
event.preventDefault();
657+
}
658+
}
659+
638660
private renderUrlDialog() {
639661
return html`
640662
<sl-dialog
641663
label="Create New Archive"
642664
class="[--header-spacing:theme(spacing.3)] [--width:70ch]"
643665
?open=${this.showCreateDialog}
666+
@sl-request-close=${this.onUrlDialogRequestClose}
644667
@sl-hide=${() => (this.showCreateDialog = false)}
645668
>
646669
<form
@@ -659,24 +682,37 @@ class ArchiveNow extends LitElement {
659682
input.value = "";
660683
this.showCreateDialog = false;
661684
662-
this.hint = "page-load";
685+
if (this.isEmpty) {
686+
this.isEmpty = false;
687+
this.showHint = true;
688+
this.hint = "first-load";
689+
} else {
690+
this.hint = "page-load";
691+
}
663692
this.addLinky();
664693
}}
665694
>
695+
<div class="flex flex-col">
666696
<div class="flex items-end gap-3 px-3 pb-3">
667697
<sl-input
668698
name="url"
669699
class="flex-1"
670700
label="Enter a URL"
671701
placeholder=${DEFAULT_URL.replace(/\/$/, "")}
672-
type="url"
673-
autocomplete="off"
702+
type="text"
703+
autocomplete="url"
704+
inputmode="url"
705+
spellcheck="false"
674706
required
675707
></sl-input>
676708
<sl-button type="submit" variant="primary"
677709
>Start Archiving</sl-button
678710
>
679711
</div>
712+
${!this.isEmpty ? html`
713+
<div class="px-3 pb-2 text-sm">Note: Your previous archive will be cleared out. Be sure to download it if you want to keep it!</div>
714+
` : ``}
715+
</div>
680716
</form>
681717
</sl-dialog>
682718
`;

0 commit comments

Comments
 (0)