Some frontend and file fetch from os

This commit is contained in:
jorenchik
2024-08-04 20:58:06 +03:00
parent 68caae929a
commit eeb42b6a32
7 changed files with 183 additions and 59 deletions

View File

@@ -3,6 +3,8 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"regexp"
) )
// App struct // App struct
@@ -25,3 +27,31 @@ func (a *App) startup(ctx context.Context) {
func (a *App) Greet(name string) string { func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, It's show time!", name) return fmt.Sprintf("Hello %s, It's show time!", name)
} }
type File struct{
Name string;
IsDir bool;
}
// Greet returns a greeting for the given name
func (a *App) GetRepoFiles() []File {
dirPath := "/home/jorenchik/Code/mdemory/memorybase/"
dirEntries, err := os.ReadDir(dirPath)
if (err != nil) {
return []File{}
}
files := []File{}
exp, err := regexp.Compile(".+\\.mdem")
for _, el := range dirEntries {
if (err != nil) {
continue
}
if (el.IsDir() || exp.Match([]byte(el.Name()))) {
file := File{}
file.Name = el.Name()
file.IsDir = el.IsDir()
files = append(files, file)
}
}
return files
}

View File

@@ -9,39 +9,54 @@
<div id="app"> <div id="app">
<div class="main-layout"> <div class="main-layout">
<div> <div>
<h3>Memorybase</h3> <h3>memorybase</h3>
<div class="file-menus">
<h4 class="sidebar-heading">mdems</h4>
<div>
<div id="deck-list" class="deck-list">
<div class="mbase-actions">
<input class="repo-input" type="text" name="file" value="">
<a id="reload-files" href="#">
Reload
</a>
</div>
<!--<a class="deck-link" href="#">-->
<!-- <div class="deck">-->
<!-- <span>&gt;</span>-->
<!-- <span>math</span>-->
<!-- </div>-->
<!--</a>-->
<!--<a class="deck-link" href="#">-->
<!-- <div class="deck">-->
<!-- cpp-->
<!-- </div>-->
<!--</a>-->
</div>
</div>
<div>
<h4 class="sidebar-heading">decks</h4>
<div class="deck-list"> <div class="deck-list">
<a href="#"> <a class="deck-link" href="#">
<div class="deck">
<span>&gt;</span>
<span>math</span>
</div>
</a>
<a href="#">
<div class="deck">
<span>&gt;</span>
<span>2nd_semester</span>
</div>
</a>
<a href="#">
<div class="deck">
python
</div>
</a>
<a href="#">
<div class="deck">
combinatorics
</div>
</a>
<a href="#">
<div class="deck"> <div class="deck">
cpp cpp
</div> </div>
</a> </a>
<a class="deck-link" href="#">
<div class="deck">
python
</div>
</a>
<a class="deck-link" href="#">
<div class="deck">
tikli
</div>
</a>
</div>
</div>
</div> </div>
</div> </div>
<div> <div>
<h2>countries: Flashcards</h2> <h2>flashcards: countries</h2>
<div class="deck-listing"> <div class="deck-listing">
<div class="flashcard"> <div class="flashcard">
<span>&gt;</span> <span>&gt;</span>

View File

@@ -10,7 +10,7 @@
} }
.main-layout .deck-list { .main-layout .deck-list {
padding: 1rem; padding: .5rem 1rem;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
/*gap: .5rem;*/ /*gap: .5rem;*/
@@ -60,3 +60,33 @@ h1, h2, h3, h4 {
margin-left: 15px; margin-left: 15px;
} }
.repo-input {
width: 99%;
height: 25px;
min-width: 0;
}
.mbase-actions {
display: flex;
align-items: center;
gap: .5rem;
margin-bottom: 1rem;
}
.mbase-actions a {
font-size: .8rem;
display: block;
}
.sidebar-heading {
font-size: .9rem;
display: flex;
margin: 0;
padding: 0 1rem;
}
.file-menus > div {
margin-bottom: 1.5rem;
}

View File

@@ -1,40 +1,65 @@
import './style.css'; import './style.css';
import './app.css'; import './app.css';
import logo from './assets/images/logo-universal.png'; import {GetRepoFiles} from '../wailsjs/go/main/App';
import {Greet} from '../wailsjs/go/main/App'; import {main} from '../wailsjs/go/models';
// Setup the greet function interface DeckFile {
window.greet = function () { Name: string;
// Get name IsDir: boolean;
let name = nameElement!.value; }
// Check if the input is empty function fetchFiles() {
if (name === "") return; GetRepoFiles().then((result: main.File[]) => {
const files: DeckFile[] = result as DeckFile[]
// Call App.Greet(name) setDecklistFiles(files)
try {
Greet(name)
.then((result) => {
// Update result with data back from App.Greet()
resultElement!.innerText = result;
})
.catch((err) => {
console.error(err);
}); });
} catch (err) { }
console.error(err); fetchFiles()
let decklist: Element | null = document.querySelector("#deck-list");
function setDecklistFiles(files: DeckFile[]) {
if (decklist) {
let deckFileAnchors = decklist.querySelectorAll(".deck-link")
deckFileAnchors.forEach(i => {
i.remove();
});
for (let i = 0; i < files.length; i++) {
let element = document.createElement('a');
let angleHtml = ''
if (files[i].IsDir) {
angleHtml = "<span angle='true'>></span>"
} }
}; element.setAttribute("href", "#")
element.setAttribute("class", "deck-link")
element.innerHTML = `
<div class="deck">
${ angleHtml }
${files[i].Name}
</div>
`
decklist.appendChild(element)
if (files[i].IsDir) {
let angle: HTMLElement | null = element.querySelector("[angle='true']")
element.addEventListener("click", _clickable => {
let style: CSSStyleDeclaration | undefined = angle?.style
if (style) {
if (style["rotate"] == "90deg") {
style["rotate"] = "";
} else {
style["rotate"] = "90deg";
}
}
})
}
}
}
}
let btnReload: Element | null = document.querySelector("#reload-files");
//document.querySelector('#app')!.innerHTML = ` btnReload?.addEventListener("click", _e => {
//`; fetchFiles();
(document.getElementById('logo') as HTMLImageElement).src = logo; })
let nameElement = (document.getElementById("name") as HTMLInputElement);
nameElement.focus();
let resultElement = document.getElementById("result");
declare global { declare global {
interface Window { interface Window {

View File

@@ -1,4 +1,7 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
import {main} from '../models';
export function GetRepoFiles():Promise<Array<main.File>>;
export function Greet(arg1:string):Promise<string>; export function Greet(arg1:string):Promise<string>;

View File

@@ -2,6 +2,10 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
export function GetRepoFiles() {
return window['go']['main']['App']['GetRepoFiles']();
}
export function Greet(arg1) { export function Greet(arg1) {
return window['go']['main']['App']['Greet'](arg1); return window['go']['main']['App']['Greet'](arg1);
} }

View File

@@ -0,0 +1,17 @@
export namespace main {
export class File {
static createFrom(source: any = {}) {
return new File(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
}
}
}