SandpointsEditPage/src/App.svelte

112 lines
3.5 KiB
Svelte
Raw Normal View History

2021-03-25 16:02:55 +01:00
<script>
import SpTitle from './SpTitle.svelte'
import SpHasTiers from './SpHasTiers.svelte'
2021-04-28 17:09:45 +02:00
import SpHasWhat from './SpHasWhat.svelte'
import SpHasCandidates from './SpHasCandidates.svelte'
2021-03-25 16:02:55 +01:00
import { onMount } from 'svelte';
let v = "loading...";
let relpath = "";
let relpermalink = "";
let protocol = "";
let title = "Foo bar";
2021-04-28 17:09:45 +02:00
let tiers = [];
let tier = {};
let hastiers = "";
let candidates = [];
2021-04-28 17:09:45 +02:00
let hases = [];
function keyUp(e) {
if (e.key == "Escape") {
window.history.back()
2021-04-14 02:14:39 +02:00
}
2021-04-13 01:46:33 +02:00
}
function diffArrr(arr, arrr) {
let diff = new Set(arr)
for (let e of arrr) {
diff.delete(e)
}
return Array.from(diff)
2021-03-25 16:02:55 +01:00
}
2021-04-28 17:09:45 +02:00
function newHasTiers(h) {
hastiers = h.detail.substring(1)
tiers = []
if (hastiers != "Has new") {
candidates = METASP[hastiers].tiers
}
}
2021-04-24 01:54:25 +02:00
function loadHugoPageMetadata() {
2021-03-25 16:02:55 +01:00
var el = document.createElement('script');
el.onload = ()=> {
v = repo.content;
2021-03-27 17:02:33 +01:00
if (v.startsWith("\n")) {
v = v.substring(1)
}
relpath = repo.path;
relpermalink = repo.relpermalink
protocol = document.location.protocol.substring(0,4)
2021-04-28 17:09:45 +02:00
hases = Object.keys(METASP)
let tkey = Object.keys(repo.frontmatter).filter(t => t.toLowerCase() == "title")[0]
title = repo.frontmatter[tkey]
let xastiers = Object.keys(repo.frontmatter).filter(t => t.toLowerCase().startsWith("has_"))
if (xastiers.length == 1) {
2021-04-24 01:51:59 +02:00
hastiers = xastiers[0].substr(4)
tiers = []
repo.frontmatter[xastiers[0]].forEach(t => {
METASP[hastiers].tiers.forEach(f => {
if (f.file == t) {
tiers.push(f)
}
})
})
candidates = diffArrr(METASP[hastiers].tiers, tiers)
}
2021-03-25 16:02:55 +01:00
}
el.src = `../js/repo/${location.hash.substring(1)}.js`
document.body.appendChild(el)
2021-03-25 16:02:55 +01:00
}
function addToCandidatesRemoveFromTiers(tier) {
console.log("addToCandidates", tier.detail)
tiers = tiers.filter(t => t !== tier.detail);
candidates = [...candidates, tier.detail]
}
function addToTiersRemoveFromCandidates(v) {
console.log("addToTiers", v.detail)
let value = v.detail
const tier = candidates.filter(t => t.file == value)
if (tier.length > 0) {
tiers = [...tiers, tier[0]]
candidates = candidates.filter(t=> t != tier[0])
}
}
2021-04-28 17:09:45 +02:00
onMount(()=> {loadHugoPageMetadata()})
2021-03-25 16:02:55 +01:00
</script>
<svelte:window on:keyup={keyUp}/>
2021-03-25 16:02:55 +01:00
<main id="sandpoints">
<form>
<SpTitle title={title} />
2021-04-28 17:09:45 +02:00
<SpHasWhat on:hasTiersSelected={newHasTiers} hases={hases} hastiers={hastiers} />
<SpHasTiers on:addToCandidatesRemoveFromTiers={addToCandidatesRemoveFromTiers} hastiers={hastiers} candidates={candidates} tiers={tiers}/>
<SpHasCandidates on:addToTiersRemoveFromCandidates={addToTiersRemoveFromCandidates} candidates={candidates} />
2021-04-14 02:14:39 +02:00
<label for="content">Content:</label>
<textarea bind:value={v} oninput='this.style.height = "";this.style.height = this.scrollHeight + 3 + "px"'></textarea>
2021-03-27 17:02:33 +01:00
{#if document.location.protocol.substring(0,4) != "file"}
<label for="publish">Publish</label>
<input type="checkbox" id="publish" name="publish" />
{/if}
2021-03-25 16:02:55 +01:00
<label for="offline">Offline</label>
<input type="checkbox" id="offline" name="offline" />
<input type="hidden" name="relpermalink" bind:value={relpermalink} />
<input type="hidden" name="relpath" bind:value={relpath} />
<input type="hidden" name="protocol" bind:value={protocol} />
2021-03-27 17:02:33 +01:00
<button id="sandpointsButton">COMMIT/SAVE</button>
2021-03-25 16:02:55 +01:00
</form>
</main>