Skip to content

Commit

Permalink
merging redirect-bug branch
Browse files Browse the repository at this point in the history
  • Loading branch information
YunPearce committed Sep 27, 2024
2 parents 7242852 + c028ad8 commit 9158861
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 9 deletions.
6 changes: 4 additions & 2 deletions pkg/arvo/app/neo.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -1564,14 +1564,16 @@
=. run (emit do-std-warp)
=. run
(emit (do-card #/[p/our.bowl] %make %root ~ ~))
=. run
(emit (do-card #/[p/our.bowl]/cod/std/src/imp %make %sig `sig/!>(~) ~))
=. run
(emit (do-card #/[p/our.bowl]/sky %make %sky ~ ~))
=. run
(emit (do-card #/[p/our.bowl]/srv/hawk %make %hawk-eyre ~ ~))
=. run
(emit (do-card #/[p/our.bowl]/blue %make %blue ~ ~))
(emit (do-card #/[p/our.bowl]/blue %make %blue ~ (~(gas by *crew:neo) src/#/[p/our.bowl]/cod/std/src/imp ~)))
=. run
(emit (do-card #/[p/our.bowl]/mast %make %mast ~ ~))
(emit (do-card #/[p/our.bowl]/mast %make %mast ~ (~(gas by *crew:neo) src/#/[p/our.bowl]/cod/std/src/imp ~)))
=. run
(emit (do-card #/[p/our.bowl]/self %make %self ~ ~))
=. run
Expand Down
154 changes: 150 additions & 4 deletions pkg/arvo/neo/cod/std/src/fil/wi-nd.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ customElements.define(
`
this.intervalId = null
}
connectedCallback() {
$(this.gid('searchbar')).off()
$(this.gid('searchbar')).on('submit', (e) => {
e.preventDefault()
this.setAttribute('here', $(this.gid('input-here')).val())
this.setAttribute('renderer', this.strategies[0])
this.rebuildIframe()
})
$(this.gid('input-here')).off()
$(this.gid('input-here')).on('focusout', (e) => {
$(this).removeAttr('searching')
})
$(this.gid('input-here')).on('blur', (e) => {
$(this).removeAttr('searching')
})
$(this.gid('menu-toggle')).off()
$(this.gid('menu-toggle')).on('click', (e) => {
this.toggleAttribute('menu')
})
this.intervalId = null
}
connectedCallback() {
$(this.gid('searchbar')).off()
$(this.gid('searchbar')).on('submit', (e) => {
Expand All @@ -146,6 +167,19 @@ customElements.define(
this.toggleAttribute('menu')
})

$(this.gid('dragger')).off()
$(this.gid('dragger')).on('dragstart', (e) => {
e.originalEvent.dataTransfer.setData(
'text/plain',
this.getAttribute('wid')
)
})
$(this.gid('dragger')).on('dragenter', (e) => {
$(this).emit('drag-start')
})
$(this.gid('dragger')).on('dragend', (e) => {
$(this).emit('drag-end')
})
$(this.gid('dragger')).off()
$(this.gid('dragger')).on('dragstart', (e) => {
e.originalEvent.dataTransfer.setData(
Expand Down Expand Up @@ -202,6 +236,22 @@ customElements.define(
this.setAttribute('wid', `${Date.now()}`)
this.buildMenu()

// poll iframes for changes every 350ms
this.intervalId = setInterval(() => {
let here = this.getAttribute('here')
let favicon = this.getAttribute('favicon')
let tabTitle = this.getAttribute('tab-title')
$(this.gid('tabs'))
.children()
.each(function () {
this.contentWindow.postMessage({
messagetype: 'sky-poll',
here,
favicon,
tabTitle
})
})
}, 350)
// poll iframes for changes every 350ms
this.intervalId = setInterval(() => {
let here = this.getAttribute('here')
Expand Down Expand Up @@ -402,6 +452,7 @@ customElements.define(
if (words.length != 2) {
words = ['b', 'b-error']
}
return words[1].split('-').slice(1).join(' ')
}
}
}
Expand All @@ -419,6 +470,23 @@ customElements.define(
}
return r
}
async checkUrl(url) {
try {
let response = await fetch(url, { method: 'GET' })
if (response.ok) {
if (response.redirected) {
return false
} else {
return true
}
} else {
return false
}
} catch (error) {
console.error('Fetch error:', error)
return false
}
}
createIframe(prefix, here, open) {
let el = document.createElement('iframe')
el.setAttribute('prefix', prefix)
Expand All @@ -436,10 +504,22 @@ customElements.define(
})
return el
}
rebuildIframe() {
$(this.gid('tabs')).children().remove()
let frame = this.createIframe(this.renderer, this.here, true)
$(this.gid('tabs')).append(frame)
async rebuildIframe() {
let url =
this.renderer === '/self'
? window.location.origin + this.here
: window.location.origin + this.renderer + this.here
let isLoading = await this.checkUrl(url)
if (isLoading) {
$(this.gid('tabs')).children().remove()
let frame = this.createIframe(this.renderer, this.here, true)
$(this.gid('tabs')).append(frame)
} else {
$(this.gid('tabs')).children().remove()
let frame = this.createIframe(`/tree`, this.here, true)
$(this.gid('menu-toggle')).text(`tree`)
$(this.gid('tabs')).append(frame)
}
}
registerServiceWorker(iframe, prefix) {
// for convenience, this part is inject by wi-nd.
Expand Down Expand Up @@ -540,6 +620,43 @@ customElements.define(
})
breadcrumbs.append(spacer)
}
buildMenu() {
let menu = this.gid('menu')
$(menu).children().remove()
//
/*let top = $(`
`
iframeDoc.body.appendChild(inlineScript)
}
buildBreadcrumbs() {
let breadcrumbs = $(this.gid('breadcrumbs'))
breadcrumbs.children().remove()
//
this.path.forEach((p, i) => {
let chevron = $(document.createElement('span'))
chevron.addClass('s-2 f4 o6 fc ac jc no-select')
if (i > 0) {
chevron.text('›')
}
breadcrumbs.append(chevron)
//
let crumb = $(document.createElement('button'))
crumb.addClass((i === 0 ? 'p-1' : 'p1') + ' b2 hover br1 s-1 f2')
crumb.text(i === 0 && this.path[0].startsWith('~') ? '/' : this.path[i])
crumb.on('click', () => {
$(this).attr('here', '/' + this.path.slice(0, i + 1).join('/'))
$(this).attr('renderer', this.strategies[0])
this.rebuildIframe()
})
breadcrumbs.append(crumb)
})
let spacer = $(document.createElement('button'))
spacer.addClass('grow b2 br1 hover')
spacer.on('click', () => {
$(this).attr('searching', '')
})
breadcrumbs.append(spacer)
}
buildMenu() {
let menu = this.gid('menu')
$(menu).children().remove()
Expand Down Expand Up @@ -573,6 +690,7 @@ customElements.define(
</div>
</div>
`);*/
let top = $(`
let top = $(`
<div class="fc g1">
<div class="fr g3 ac js">
Expand All @@ -589,6 +707,8 @@ customElements.define(
</div>
`)
/*$(top).find('h4').text(this.renderer);
`)
/*$(top).find('h4').text(this.renderer);
if (this.strategies.includes(this.renderer)) {
$(top).find('#bm-save-btn').addClass('hidden')
}
Expand All @@ -601,6 +721,9 @@ customElements.define(
$(top).find('#bm-del-btn').on('click', (e) => {
$(this).emit('unbookmark-renderer', this.renderer)
});*/
//menu.appendChild(top.get(0));
//
let bookmarks = $(`
//menu.appendChild(top.get(0));
//
let bookmarks = $(`
Expand All @@ -609,6 +732,22 @@ customElements.define(
<div class="frw g2 ac js">
</div>
</div>
`)
//
this.strategies.forEach((s) => {
let bookmark = $(`<button class="b1 br1 bd1 p-1 wfc"></button>`)
bookmark.text(this.labelLookup(s) || s)
$(bookmark).on('click', (e) => {
$(this).attr('renderer', s)
})
if (s === this.renderer) {
$(bookmark).addClass('toggled')
}
bookmarks.find('.frw').append(bookmark)
})
menu.appendChild(bookmarks.get(0))
//
let any = $(`
`)
//
this.strategies.forEach((s) => {
Expand Down Expand Up @@ -636,5 +775,12 @@ customElements.define(
})
menu.appendChild(any.get(0))
}
`)
any.on('submit', (e) => {
e.preventDefault()
$(this).attr('renderer', any.find('input').val())
})
menu.appendChild(any.get(0))
}
}
)
29 changes: 28 additions & 1 deletion pkg/arvo/neo/cod/std/src/imp/blue.hoon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/@ eyre-reqs
/- serv=sky-server
/- srv=server
/- su=shrub-utils
^- kook:neo
|%
++ state pro/%sig
Expand All @@ -11,7 +12,20 @@
:~ :- [|/%ta |]
[pro/%eyre-task (sy %rely ~)]
==
++ deps *deps:neo
++ deps
%- ~(gas by *band:neo)
:~ :- %src
^- fief:neo
:- req=&
^- quay:neo
:- [only/%sig ~]
^- (unit port:neo)
:+ ~ %y
%- ~(gas by *lads:neo)
:~ :- [|/%tas |]
`lash:neo`[only/%hoon ~]
==
==
++ form
|_ [=bowl:neo =aeon:neo =pail:neo]
++ init
Expand Down Expand Up @@ -44,8 +58,21 @@
::
:: handle everything under /blue
=/ renderer (snag 1 inner)
=/ lore q:(~(got by deps.bowl) %src)
=/ has-renderer
!=(~ (get-pail-saga-by-pith:su lore /[renderer]))
?^ renderer
~|('Second iota in URL must be a @tas.' !!)
?. has-renderer
:_ sig/!>(~)
=/ =pith:neo #/[p/our.bowl]/$/eyre
=/ loc
(en-cord:pith:neo (welp /tree (tail (tail inner))))
:~
[pith %poke eyre-sign/!>([eyre-id %head 307 ['Location' loc]~])]
[pith %poke eyre-sign/!>([eyre-id %data ~])]
[pith %poke eyre-sign/!>([eyre-id %done ~])]
==
:_ sig/!>(~)
:~ :* (welp here.bowl [[%ta eyre-id] ~])
%make
Expand Down
28 changes: 27 additions & 1 deletion pkg/arvo/neo/cod/std/src/imp/mast.hoon
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
/@ ui-event
/@ mast-bind
/- su=shrub-utils
/* mast-js
=<
^- kook:neo
|%
++ state [%pro %sig]
++ poke (sy %mast-bind %eyre-task %eyre-chan-task %gift ~)
++ deps *deps:neo
++ deps
%- ~(gas by *band:neo)
:~ :- %src
^- fief:neo
:- req=&
^- quay:neo
:- [only/%sig ~]
^- (unit port:neo)
:+ ~ %y
%- ~(gas by *lads:neo)
:~ :- [|/%tas |]
`lash:neo`[only/%hoon ~]
==
==
++ kids
:+ ~ %y
%- my
Expand Down Expand Up @@ -72,10 +86,14 @@
(~(got by endpoints.rig) url)
=/ =rope (mug bind)
=/ =boat ship.src.bowl
=/ lore q:(~(got by deps.bowl) %src)
=/ renderer=(unit pail:neo) (get-pail-saga-by-pith:su lore /[view.bind])
?. ?| =(our.bowl boat)
(~(has in public.rig) rope)
==
[(~(make-403 res bowl) rid) pail]
=/ has-renderer !=(~ renderer)
?. has-renderer [(~(make-tree-redirect res bowl) rid src.bind) pail]
=/ at=pith:neo (~(session moor our.bowl) rope boat)
=/ =made:neo [view.bind ~ (my [%src src.bind] ~)]
=/ wat (~(get by waiting.rig) [rope boat])
Expand Down Expand Up @@ -291,6 +309,14 @@
[307 ['Location' '/~/login?redirect='] ~]
~
::
++ make-tree-redirect
|= [rid=@ta loc=pith]
^- (list card:neo)
%^ make-direct-http-cards
rid
[307 ['Location' (en-cord:pith:neo (welp /tree loc))] ~]
~
::
++ make-direct-http-cards
|= [rid=@ta hed=response-header:http dat=(unit octs)]
^- (list card:neo)
Expand Down
2 changes: 1 addition & 1 deletion pkg/arvo/neo/cod/std/src/imp/sky.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
:_ sig/!>(~)
:~
[#/[p/our.bowl]/sky/strategy/[p/our.bowl] %make %order `order/!>(~) ~]
[#/[p/our.bowl]/sky/strategy/[p/our.bowl]/home %make %order `order/!>([#/hawk ~]) ~]
[#/[p/our.bowl]/sky/strategy/[p/our.bowl]/home %make %order `order/!>([#/self ~]) ~]
[#/[p/our.bowl]/profiles [%make %profiles `[%sig !>(~)] ~]]
[#/[p/our.bowl]/profiles/default [%make %sig `[%sig !>(~)] ~]]
[#/[p/our.bowl]/homepage [%make %homepage `[%homepage !>([#/default ~])] (malt ~[[%profiles #/[p/our.bowl]/profiles]])]]
Expand Down

0 comments on commit 9158861

Please sign in to comment.