File tree Expand file tree Collapse file tree 5 files changed +14
-34
lines changed Expand file tree Collapse file tree 5 files changed +14
-34
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,18 @@ export default function App() {
7878 return < div > Could not load a data source. You have to pass a valid source in the url, eg: < a href = { defaultUrl } > { defaultUrl } </ a > .</ div >
7979 }
8080
81+ /* Send a message to the parent window to synchronize the query string
82+ *
83+ * Hugging Face Space impose some restrictions to the static apps that are hosted on their platform,
84+ * with respect to the URLs. Only hash and query strings can be changed, and doing so requires
85+ * some custom code:
86+ * https://huggingface.co/docs/hub/spaces-handle-url-parameters
87+ *
88+ * Note that the iframe has no access to the parent window's location, so
89+ * it might already by in sync, we just don't know.
90+ */
91+ window . parent . postMessage ( { queryString : window . location . search } , 'https://huggingface.co' )
92+
8193 return < ConfigProvider value = { config } >
8294 < Page source = { source } navigation = { { row, col } } />
8395 </ ConfigProvider >
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import { OAuthResult } from '@huggingface/hub'
22import { FormEvent , useEffect } from 'react'
33import HFLoginIcon from '../../assets/sign-in-with-huggingface-lg.svg'
44import { login , logout } from '../../lib/auth.js'
5- import { changeQueryString } from '../../lib/huggingfaceSource.js'
65import Search from '../Search/Search.js'
76import styles from './Home.module.css'
87
@@ -17,7 +16,7 @@ export default function Home({ auth }: { auth: OAuthResult | undefined }) {
1716 function onUrlSubmit ( event : FormEvent < HTMLFormElement > ) {
1817 event . preventDefault ( )
1918 const url = new FormData ( event . currentTarget ) . get ( 'url' ) as string
20- changeQueryString ( ` ?url=${ url } `)
19+ window . location . href = `/ ?url=${ url } `
2120 }
2221
2322 // pre-dismiss the welcome popup since user landed on the home page
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import { DatasetEntry , listDatasets } from '@huggingface/hub'
22import { ChangeEvent , useEffect , useState } from 'react'
33import { baseUrl } from '../../lib/huggingfaceSource.js'
4- import Link from '../Link/Link.js'
54import styles from './Search.module.css'
65
76export default function Search ( { accessToken } : { accessToken ?: string } ) {
@@ -38,7 +37,7 @@ export default function Search({ accessToken } : { accessToken?: string }) {
3837 < ul className = { styles . refList } >
3938 { datasets . map ( ( dataset ) =>
4039 < li key = { dataset . name } >
41- < Link url = { `${ baseUrl } /${ dataset . name } ` } > { dataset . name } </ Link >
40+ < a href = { `/?url= ${ baseUrl } /${ dataset . name } ` } > { dataset . name } </ a >
4241 </ li > ,
4342 ) }
4443 </ ul >
Original file line number Diff line number Diff line change @@ -4,17 +4,6 @@ import { getFileName } from 'hyperparam'
44
55export const baseUrl = 'https://huggingface.co/datasets'
66
7- // Hugging Face Space impose some restrictions to the static apps that are hosted on their platform,
8- // with respect to the URLs. Only hash and query strings can be changed, and doing so requires
9- // some custom code:
10- // https://huggingface.co/docs/hub/spaces-handle-url-parameters
11- export function changeQueryString ( queryString : string ) {
12- const url = new URL ( window . location . href )
13- url . search = queryString
14- window . parent . postMessage ( { queryString } , 'https://huggingface.co' )
15- window . location . assign ( url )
16- }
17-
187function getSourceParts ( url : HFUrl ) : SourcePart [ ] {
198 const sourceParts : SourcePart [ ] = [ {
209 sourceId : `${ baseUrl } /${ url . repo } /tree/${ url . branch } /` ,
You can’t perform that action at this time.
0 commit comments