Skip to content

Commit

Permalink
feat: create matic fucntion
Browse files Browse the repository at this point in the history
  • Loading branch information
sanda0 committed Jun 6, 2024
1 parent 139db55 commit 7c853e5
Show file tree
Hide file tree
Showing 12 changed files with 647 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ frontend/dist

*.txt

*.matic.json
20 changes: 20 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ package main
import (
"context"
"fmt"
"log"

"github.com/sanda0/webmatic/webmaticlib"
)

type Response struct {
Status int `json:"status"`
Data interface{} `json:"data"`
}

// App struct
type App struct {
ctx context.Context
Expand All @@ -29,3 +37,15 @@ func (a *App) Greet(name string) string {
func (a *App) FileUpload(fileName string) int {
return 100
}

func (a *App) SaveMatic(name string, autor string) Response {
fileName, err := webmaticlib.SaveMatic(name, autor)
if err != nil {
log.Println(err.Error())
return Response{
Status: 500,
Data: err.Error(),
}
}
return Response{Status: 200, Data: fileName}
}
2 changes: 1 addition & 1 deletion frontend/src/components/Button2.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function Button2(props) {
return (
<button onClick={(e)=>{props.onClick(e)}} className="flex items-center w-full gap-2 p-2 m-1 text-center border-2 rounded-md text-slate-700 border-slate-700 hover:bg-white hover:text-slate-700 ">
<button onClick={(e)=>{props.onClick(e)}} className="flex items-center justify-center w-full gap-2 p-2 m-1 text-center border-2 rounded-md text-slate-700 border-slate-700 hover:bg-white hover:text-slate-700 ">
{props.children}
</button>
);
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/pages/Editor.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export default function Editor(){

}
26 changes: 21 additions & 5 deletions frontend/src/pages/NewMatic.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { useState } from "react";
import Input from "../components/Input";
import Button2 from "../components/Button2";
import { Save } from "lucide-react";
import { SaveMatic } from "../../wailsjs/go/main/App";

export default function NewMatic() {

const [name, setname] = useState("");
const [author, setAuthor] = useState("");

function save(e){
console.log(name)
console.log(author)
}
function save(e) {
console.log(name);
console.log(author);
SaveMatic(name, author).then((r)=>{
console.log(r);
if(r.status == 200){

}
})
}

return (
<div className="content-center h-screen">
Expand All @@ -30,7 +39,14 @@ export default function NewMatic() {
></Input>
<div className="flex">
<div className="w-[100px] ms-auto me-3">
<Button2 onClick={(e)=>{save(e)}}> Save </Button2>
<Button2
onClick={(e) => {
save(e);
}}
>
{" "}
<Save /> Save{" "}
</Button2>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {main} from '../models';

export function FileUpload(arg1:string):Promise<number>;

export function Greet(arg1:string):Promise<string>;

export function SaveMatic(arg1:string,arg2:string):Promise<main.Response>;
4 changes: 4 additions & 0 deletions frontend/wailsjs/go/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export function FileUpload(arg1) {
export function Greet(arg1) {
return window['go']['main']['App']['Greet'](arg1);
}

export function SaveMatic(arg1, arg2) {
return window['go']['main']['App']['SaveMatic'](arg1, arg2);
}
19 changes: 19 additions & 0 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export namespace main {

export class Response {
status: number;
data: any;

static createFrom(source: any = {}) {
return new Response(source);
}

constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.status = source["status"];
this.data = source["data"];
}
}

}

4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"embed"
"os"

"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
Expand All @@ -12,6 +13,9 @@ import (
var assets embed.FS

func main() {

os.Mkdir("matics", os.FileMode(0777))

// Create an instance of the app structure
app := NewApp()

Expand Down
Loading

0 comments on commit 7c853e5

Please sign in to comment.