diff --git a/backend/api.go b/backend/api.go index f290b94..d2ef499 100644 --- a/backend/api.go +++ b/backend/api.go @@ -2,7 +2,7 @@ package main type FilesContentRequest struct { Password string `json:"password"` - // TODO: add file + File string `json:"file"` } type FilesContentResponse struct { diff --git a/backend/handlers.go b/backend/handlers.go index 780dc4c..f8ca6eb 100644 --- a/backend/handlers.go +++ b/backend/handlers.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "log" "net/http" "sync" @@ -23,6 +24,9 @@ func filesContentHandler(w http.ResponseWriter, r *http.Request) { return } + fmt.Println("File: ", req.File) + fmt.Println("Password: ", req.Password) + fileContent, err := readFromFile(defaultFile) if err != nil { http.Error(w, "file not found", http.StatusNotFound) diff --git a/electron/main.js b/electron/main.js index 8e67a0e..f41a103 100644 --- a/electron/main.js +++ b/electron/main.js @@ -32,9 +32,9 @@ app.whenReady().then(() => { await axios.put('http://localhost:8080/files/save', data); }); - ipcMain.handle('files-content', async (event, password) => { + ipcMain.handle('files-content', async (event, data) => { try { - const response = await axios.post('http://localhost:8080/files/content', { password }); + const response = await axios.post('http://localhost:8080/files/content', data); return response.data.content; } catch (error) { console.error('Error getting the content of the file with the password:', error); diff --git a/electron/preload.js b/electron/preload.js index 9f18ca1..fbf9a5f 100644 --- a/electron/preload.js +++ b/electron/preload.js @@ -1,6 +1,6 @@ const { contextBridge, ipcRenderer } = require('electron/renderer'); contextBridge.exposeInMainWorld('api', { - filesContent: (password) => ipcRenderer.invoke('files-content', password), + filesContent: (data) => ipcRenderer.invoke('files-content', data), filesSave: (data) => ipcRenderer.invoke('files-save', data), }); diff --git a/frontend/src/components/MainComponent.js b/frontend/src/components/MainComponent.js index 38c3d67..9f2a375 100644 --- a/frontend/src/components/MainComponent.js +++ b/frontend/src/components/MainComponent.js @@ -3,16 +3,10 @@ import React, { useState, useRef } from 'react'; const TextAreaComponent = () => { const [textAreaValue, setTextAreaValue] = useState(''); const [password, setPassword] = useState(''); + const [file, handleFileUpload] = useState(''); const fileInputRef = useRef(null); - const handleFileUpload = (event) => { - const file = event.target.files[0]; - if (file) { - console.log('Selected file:', file); - } - }; - const openFileDialog = () => { fileInputRef.current.click(); }; @@ -24,7 +18,7 @@ const TextAreaComponent = () => { }; const handleFetchContent = async () => { - const content = await window.api.filesContent(password); + const content = await window.api.filesContent({file: file, password:password}); setTextAreaValue(content); }; @@ -36,7 +30,7 @@ const TextAreaComponent = () => { type="file" ref={fileInputRef} style={{ display: 'none' }} - onChange={handleFileUpload} + onChange={(e) => handleFileUpload(e.target.value)} />