generated from com-480-data-visualization/com-480-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:com-480-data-visualization/com-48…
…0-project-statiswiss
- Loading branch information
Showing
6 changed files
with
82 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,10 +55,7 @@ | |
<span class="absolute inset-y-0 right-0 flex items-center pr-3"> | ||
<img class="h-7 w-7" src="resources/sparkles.svg" alt="I'm feeling lucky" /> | ||
</span> | ||
<script> | ||
const searchForRef = {"en": "Search for a vote", "fr": "Chercher une votation", "de": "eine Abstimmung suchen"}[lang]; | ||
document.write(`<input class="placeholder:text-slate-400 h-12 text-xl block bg-white font-semibold w-full border-4 border-black rounded-full py-2 pl-12 pr-3 shadow-sm focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-xl" placeholder="${searchForRef}" type="text" name="search"/>`); | ||
</script> | ||
<input class="js-search placeholder:text-slate-400 h-12 text-xl block bg-white font-semibold w-full border-4 border-black rounded-full py-2 pl-12 pr-3 shadow-sm focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-xl" type="text" name="search"/> | ||
</label> | ||
|
||
<div class="flex-1"></div> | ||
|
@@ -73,7 +70,16 @@ | |
</select> | ||
</div> | ||
|
||
<div class="flex flex-row"> | ||
<div> | ||
<div class="js-search-loader hidden"> | ||
<div class="flex items-center justify-center py-4"> | ||
<svg class="animate-spin -ml-1 mr-3 h-8 w-8 text-black" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> | ||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle> | ||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path> | ||
</svg> | ||
</div> | ||
</div> | ||
<div class="js-search-results"></div> | ||
<div class="grid-cols-1 border-black w-auto border-4 flex-initial basis-full" id="list_refs"> | ||
</div> | ||
|
||
|
@@ -107,5 +113,7 @@ | |
} | ||
})(); | ||
</script> | ||
<script src="https://unpkg.com/[email protected]/dist/browser.bundle.js"></script> | ||
<script src="resources/search.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(() => { | ||
function debounce(func, ms = 100) { | ||
let timeout; | ||
return function() { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => func.apply(this, arguments), ms); | ||
}; | ||
} | ||
|
||
const search = document.querySelector('.js-search'); | ||
search.placeholder = {"en": "Search for a vote", "fr": "Chercher une votation", "de": "Eine Abstimmung suchen"}[lang]; | ||
|
||
/** @type {import("convex/browser")["ConvexClient"]} */ | ||
const ConvexClient = convex.ConvexClient; | ||
const client = new ConvexClient('https://artful-minnow-484.convex.cloud'); | ||
/** @type {import("../../convex/_generated/api")["api"]} */ | ||
const api = convex.anyApi; | ||
|
||
const listAllResults = document.querySelector('#list_refs'); | ||
const listSearchResults = document.querySelector('.js-search-results'); | ||
const loader = document.querySelector('.js-search-loader'); | ||
|
||
const doQuery = debounce(async (query) => { | ||
console.log('searching', query) | ||
const results = await client.action(api.search.default, { query }); | ||
|
||
if (query !== search.value.trim()) return; | ||
console.log(results) | ||
|
||
let html = ''; | ||
for (const row of results) { | ||
html += showVote(row, lang); | ||
} | ||
|
||
loader.style.display = 'none'; | ||
listSearchResults.innerHTML = html; | ||
}); | ||
|
||
search.addEventListener('input', async () => { | ||
listSearchResults.innerHTML = ''; | ||
const query = search.value.trim(); | ||
if (query === '') { | ||
listAllResults.style.display = 'block'; | ||
loader.style.display = 'none'; | ||
return; | ||
} | ||
|
||
listAllResults.style.display = 'none'; | ||
loader.style.display = 'block'; | ||
|
||
doQuery(query); | ||
}); | ||
|
||
})(); |