mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
Some frontend and file fetch from os
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
|
|||||||
@@ -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="deck-list">
|
<div class="file-menus">
|
||||||
<a href="#">
|
<h4 class="sidebar-heading">mdems</h4>
|
||||||
<div class="deck">
|
<div>
|
||||||
<span>></span>
|
<div id="deck-list" class="deck-list">
|
||||||
<span>math</span>
|
<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>></span>-->
|
||||||
|
<!-- <span>math</span>-->
|
||||||
|
<!-- </div>-->
|
||||||
|
<!--</a>-->
|
||||||
|
<!--<a class="deck-link" href="#">-->
|
||||||
|
<!-- <div class="deck">-->
|
||||||
|
<!-- cpp-->
|
||||||
|
<!-- </div>-->
|
||||||
|
<!--</a>-->
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</div>
|
||||||
<a href="#">
|
<div>
|
||||||
<div class="deck">
|
<h4 class="sidebar-heading">decks</h4>
|
||||||
<span>></span>
|
<div class="deck-list">
|
||||||
<span>2nd_semester</span>
|
<a class="deck-link" href="#">
|
||||||
|
<div class="deck">
|
||||||
|
cpp
|
||||||
|
</div>
|
||||||
|
</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>
|
||||||
</a>
|
</div>
|
||||||
<a href="#">
|
|
||||||
<div class="deck">
|
|
||||||
python
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<a href="#">
|
|
||||||
<div class="deck">
|
|
||||||
combinatorics
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<a href="#">
|
|
||||||
<div class="deck">
|
|
||||||
cpp
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</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>></span>
|
<span>></span>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -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[]
|
||||||
|
setDecklistFiles(files)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
fetchFiles()
|
||||||
|
|
||||||
// Call App.Greet(name)
|
let decklist: Element | null = document.querySelector("#deck-list");
|
||||||
try {
|
function setDecklistFiles(files: DeckFile[]) {
|
||||||
Greet(name)
|
if (decklist) {
|
||||||
.then((result) => {
|
let deckFileAnchors = decklist.querySelectorAll(".deck-link")
|
||||||
// Update result with data back from App.Greet()
|
deckFileAnchors.forEach(i => {
|
||||||
resultElement!.innerText = result;
|
i.remove();
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
for (let i = 0; i < files.length; i++) {
|
||||||
console.error(err);
|
let element = document.createElement('a');
|
||||||
});
|
let angleHtml = ''
|
||||||
} catch (err) {
|
if (files[i].IsDir) {
|
||||||
console.error(err);
|
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 {
|
||||||
|
|||||||
@@ -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>;
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/mdemory-app/frontend/wailsjs/go/models.ts
Executable file
17
src/mdemory-app/frontend/wailsjs/go/models.ts
Executable 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user