Updates and more
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
function selectItem(item: {name: string, value: string}) {
|
||||
selected = item.value
|
||||
searchValue = item.name
|
||||
searchValue = ""
|
||||
open = false
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -24,6 +24,7 @@ $: console.log(availableBranches)
|
||||
async function createBranch() {
|
||||
const name = prompt("Branch name:")
|
||||
if (name) {
|
||||
selected = null
|
||||
await $pageRepo.createBranch(name)
|
||||
let inter = setInterval(() => {
|
||||
branches.reload()
|
||||
@@ -36,9 +37,9 @@ async function createBranch() {
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteBranch() {
|
||||
async function deleteBranch(con: boolean = false) {
|
||||
if (selectedBranch !== "master") {
|
||||
let conf = confirm("Are you sure you want to delete this branch?")
|
||||
let conf = con || confirm("Are you sure you want to delete this branch?")
|
||||
if(conf) {
|
||||
await $pageRepo.deleteBranch(selectedBranch)
|
||||
let inter = setInterval(() => {
|
||||
@@ -59,12 +60,21 @@ async function createFile() {
|
||||
let name = prompt("File name:", "pages/en/[Name]")
|
||||
if (name) {
|
||||
await $pageRepo.createFile(`${name}.md`, selectedBranch)
|
||||
const w = selectedBranch
|
||||
selectedBranch = "###!"
|
||||
selectedBranch = w
|
||||
reload()
|
||||
}
|
||||
}
|
||||
|
||||
function reload() {
|
||||
const w = selectedBranch
|
||||
selectedBranch = "###!"
|
||||
selectedBranch = w
|
||||
}
|
||||
|
||||
async function mergeBranch() {
|
||||
await $pageRepo.merge(selectedBranch, `Go live of ${selectedBranch}`)
|
||||
await deleteBranch(true)
|
||||
}
|
||||
|
||||
</script>
|
||||
<div class="flex flex-col h-screen overflow-scroll">
|
||||
<Navbar let:hidden let:toggle>
|
||||
@@ -84,9 +94,15 @@ async function createFile() {
|
||||
<div class="border-b border-b-gray-600 pb-2 flex justify-between">
|
||||
<TypeAheadSearch items={availableBranches} bind:selected={selectedBranch} bind:searchValue />
|
||||
<div>
|
||||
<Button on:click={createBranch}>Create Branch</Button>
|
||||
{#if selectedBranch !== "master"}
|
||||
<Button on:click={mergeBranch}>Merge Branch</Button>
|
||||
{:else}
|
||||
<Button on:click={createBranch}>Create Branch</Button>
|
||||
{/if}
|
||||
<Button on:click={createFile} color="alternative">Create File</Button>
|
||||
<Button on:click={deleteBranch} color="ghost">Delete Branch</Button>
|
||||
{#if selectedBranch !== "master"}
|
||||
<Button on:click={deleteBranch} color="ghost">Delete Branch</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{@const pagesMap = mapToMap(pages)}
|
||||
@@ -111,7 +127,7 @@ async function createFile() {
|
||||
</Card>
|
||||
<Card class="!max-w-full" style="grid-column: 2/4">
|
||||
{#if selected}
|
||||
<Editor pageId={selected} branch={selectedBranch} />
|
||||
<Editor pageId={selected} branch={selectedBranch} on:reload={reload} />
|
||||
{/if}
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -7,10 +7,14 @@
|
||||
import type {Page} from "../../types/page.ts";
|
||||
import {materialDark} from '@ddietr/codemirror-themes/material-dark.js'
|
||||
import {EditOutline} from "flowbite-svelte-icons";
|
||||
import {createEventDispatcher} from "svelte";
|
||||
|
||||
export let pageId: number;
|
||||
export let branch: string;
|
||||
$: pageFuture = $pageRepo.getPage(pageId).then(getPage);
|
||||
|
||||
let dispatcher = createEventDispatcher();
|
||||
|
||||
$: pageFuture = $pageRepo.getPage(pageId, branch).then(getPage);
|
||||
let pageContent = "";
|
||||
let page: Page | null = null;
|
||||
|
||||
@@ -21,11 +25,17 @@
|
||||
}
|
||||
|
||||
function savePage() {
|
||||
let message = window.prompt("Commit message:")
|
||||
let message = window.prompt("Commit message:", "Update " + page!.name)
|
||||
if (message) {
|
||||
$pageRepo.updatePage(pageId, pageContent, page!.sha, message)
|
||||
} else {
|
||||
alert("Commit message is required")
|
||||
$pageRepo.updatePage(pageId, pageContent, page!.sha, message, branch)
|
||||
}
|
||||
}
|
||||
|
||||
async function deletePage() {
|
||||
let message = window.prompt("Commit message:", "Delete " + page!.name)
|
||||
if (message) {
|
||||
await $pageRepo.deletePage(pageId, message, page!.sha, branch)
|
||||
dispatcher("reload")
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -37,6 +47,9 @@
|
||||
<div>
|
||||
<Toolbar class="!bg-gray-900">
|
||||
<ToolbarGroup slot="end">
|
||||
<ToolbarButton on:click={deletePage}>
|
||||
Delete
|
||||
</ToolbarButton>
|
||||
<ToolbarButton color="primary" on:click={savePage}>
|
||||
Save
|
||||
</ToolbarButton>
|
||||
|
||||
@@ -45,4 +45,12 @@ export class PageRepo {
|
||||
public async createFile(path: string, branch: string = "master"): Promise<void> {
|
||||
await fetchWithToken(this.token, `/page?branch=${branch}`, {method: "POST", body: JSON.stringify({path})})
|
||||
}
|
||||
|
||||
public async merge(branch: string, message: string): Promise<void> {
|
||||
await fetchWithToken(this.token, `/page/branch/merge`, {method: "POST", body: JSON.stringify({branch, message})})
|
||||
}
|
||||
|
||||
public async deletePage(id: number, message: string, sha: string, branch: string = "master"): Promise<void> {
|
||||
await fetchWithToken(this.token, `/page/${id}?branch=${branch}`, {method: "DELETE", body: JSON.stringify({message, sha})})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user