Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Dec 4, 2024
1 parent 8890ecf commit f8e0705
Show file tree
Hide file tree
Showing 47 changed files with 9,451 additions and 38 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Gradle Releases -> https://github.com/gradle/gradle/releases
libraryGroup=com.simiacryptus.skyenet
libraryVersion=1.2.21
libraryVersion=1.2.22
gradleVersion=7.6.1
kotlin.daemon.jvmargs=-Xmx4g
6 changes: 3 additions & 3 deletions webapp/src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const Menu: React.FC = () => {
</DropButton>
<DropdownContent>
<DropdownItem onClick={() => handleMenuClick('settings')}>Settings</DropdownItem>
<DropdownItem onClick={() => handleMenuClick('files')}>Files</DropdownItem>
<DropdownItem onClick={() => handleMenuClick('fileIndex/')}>Files</DropdownItem>
<DropdownItem onClick={() => handleMenuClick('usage')}>Usage</DropdownItem>
<DropdownItem onClick={() => handleMenuClick('threads')}>Threads</DropdownItem>
<DropdownItem onClick={() => handleMenuClick('share')}>Share</DropdownItem>
Expand All @@ -165,8 +165,8 @@ export const Menu: React.FC = () => {
<Dropdown>
<DropButton onClick={() => console.log('[Menu] About menu clicked')}>About</DropButton>
<DropdownContent>
<DropdownItem onClick={() => handleMenuClick('privacy')}>Privacy Policy</DropdownItem>
<DropdownItem onClick={() => handleMenuClick('tos')}>Terms of Service</DropdownItem>
<DropdownItem onClick={() => handleMenuClick('/privacy.html')}>Privacy Policy</DropdownItem>
<DropdownItem onClick={() => handleMenuClick('/tos.html')}>Terms of Service</DropdownItem>
</DropdownContent>
</Dropdown>

Expand Down
15 changes: 8 additions & 7 deletions webapp/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, {useEffect} from 'react';
import React from 'react';
import styled from 'styled-components';
import {useDispatch, useSelector} from 'react-redux';
import {RootState} from '../../store';
import {hideModal} from '../../store/slices/uiSlice';
import {useModal} from '../../hooks/useModal';
import {useEffect} from 'react';

const ModalOverlay = styled.div`
position: fixed;
Expand All @@ -25,21 +25,22 @@ const ModalContent = styled.div`
min-width: 300px;
max-width: 80vw;
max-height: 80vh;
min-height: 200px;
overflow: auto;
`;
const LOG_PREFIX = '[Modal]';


export const Modal: React.FC = () => {
const dispatch = useDispatch();
const {modalContent} = useModal();
const {modalOpen, modalType} = useSelector((state: RootState) => state.ui);
const {modalOpen, modalType, modalContent} = useSelector((state: RootState) => state.ui);

useEffect(() => {
console.log(`${LOG_PREFIX} Modal state changed:`, {
modalOpen,
modalType,
hasContent: !!modalContent
hasContent: !!modalContent,
contentLength: modalContent?.length || 0
});
}, [modalOpen, modalType, modalContent]);

Expand All @@ -50,9 +51,9 @@ export const Modal: React.FC = () => {

return (
<ModalOverlay onClick={() => dispatch(hideModal())}>
<ModalContent onClick={e => e.stopPropagation()}>
<ModalContent className="modal-content" onClick={e => e.stopPropagation()}>
<h2>{modalType}</h2>
<div dangerouslySetInnerHTML={{__html: modalContent}}/>
<div dangerouslySetInnerHTML={{__html: modalContent || ''}}/>
</ModalContent>
</ModalOverlay>
);
Expand Down
46 changes: 27 additions & 19 deletions webapp/src/hooks/useModal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {useDispatch} from 'react-redux';
import WebSocketService from '../services/websocket';
import {showModal as showModalAction} from '../store/slices/uiSlice';
import {useState} from "react";
import {setModalContent, showModal as showModalAction} from '../store/slices/uiSlice';
import Prism from 'prismjs';

export const useModal = () => {
const dispatch = useDispatch();
const [modalContent, setModalContent] = useState('');

// Helper to highlight code blocks
const highlightCode = () => {
Expand All @@ -25,9 +23,19 @@ export const useModal = () => {
const protocol = window.location.protocol;
const host = window.location.hostname;
const port = window.location.port;
// Handle endpoints that already have query parameters
const separator = endpoint.includes('?') ? '&' : '?';
const url = `${protocol}//${host}:${port}/${endpoint}${separator}sessionId=${WebSocketService.getSessionId()}`;
const path = window.location.pathname;
let url: string;
if (endpoint.startsWith("/")) {
url = `${protocol}//${host}:${port}${endpoint}`;
} else {
url = `${protocol}//${host}:${port}${path}${endpoint}`;
}
if (endpoint.endsWith("/")) {
url = url + WebSocketService.getSessionId() + '/';
} else {
const separator = endpoint.includes('?') ? '&' : '?';
url = url + separator + 'sessionId=' + WebSocketService.getSessionId();
}
console.log('[Modal] Constructed URL:', url);
return url;
};
Expand All @@ -41,44 +49,44 @@ export const useModal = () => {
}
console.log('[Modal] Setting initial loading state');

setModalContent('<div>Loading...</div>');
dispatch(showModalAction(endpoint));
dispatch(setModalContent('<div class="loading">Loading...</div>'));
console.log('[Modal] Fetching content from:', getModalUrl(endpoint));

fetch(getModalUrl(endpoint), {
mode: 'cors',
credentials: 'include',
headers: {
'Accept': 'text/html,application/json',
credentials: 'include'
'Accept': 'text/html,application/json,*/*'
}
})
.then(response => {
console.log('[Modal] Received response:', {
status: response.status,
statusText: response.statusText
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.text();
})
.then(content => {
console.log('[Modal] Content received, length:', content.length);
setModalContent(content);
// Highlight code after content is set
if (!content.trim()) {
throw new Error('Received empty content');
}
requestAnimationFrame(() => {
dispatch(setModalContent(content));
highlightCode();
});
})
.catch(error => {
console.error('[Modal] Failed to load content:', {
endpoint,
error: error.message,
status: error.status,
stack: error.stack
});
setModalContent('<div>Error loading content. Please try again later.</div>');
console.error('[Modal] Failed to load content:', error);
dispatch(setModalContent('<div class="error">Error loading content: ' + error.message + '</div>'));
// Keep modal open to show error
});
};
console.log('[Modal] Hook initialized');

return {openModal, getModalUrl, modalContent};
return {openModal, getModalUrl};
};
4 changes: 2 additions & 2 deletions webapp/src/services/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ThemeName} from '../types';

const LOG_PREFIX = '[AppConfig]';

const BASE_API_URL = process.env.REACT_APP_API_URL || window.location.origin;
const BASE_API_URL = process.env.REACT_APP_API_URL || (window.location.origin + window.location.pathname);
const STORAGE_KEYS = {
THEME: 'theme',
} as const;
Expand Down Expand Up @@ -70,7 +70,7 @@ export const fetchAppConfig = async (sessionId: string) => {
baseUrl: BASE_API_URL
});

const url = new URL('/appInfo', BASE_API_URL);
const url = new URL('./appInfo', BASE_API_URL);
url.searchParams.append('session', sessionId);

let response: Response;
Expand Down
11 changes: 9 additions & 2 deletions webapp/src/store/slices/uiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface UiState {
theme: ThemeName;
modalOpen: boolean;
modalType: string | null;
modalContent: string;
verboseMode: boolean;
activeTab: string;
lastUpdate?: number;
Expand All @@ -58,6 +59,7 @@ const initialState: UiState = {
theme: 'main',
modalOpen: false,
modalType: null,
modalContent: '',
verboseMode: safeStorage.setItem('verboseMode', 'false') ? false : false,
activeTab: 'chat', // Set default tab
lastUpdate: Date.now()
Expand All @@ -71,7 +73,7 @@ const logStateChange = (action: string, payload: any = null, prevState: any = nu
});
};

const uiSlice = createSlice({
export const uiSlice = createSlice({
name: 'ui',
initialState,
reducers: {
Expand Down Expand Up @@ -102,6 +104,7 @@ const uiSlice = createSlice({
});
state.modalOpen = true;
state.modalType = action.payload;
state.modalContent = 'Loading...';
},
hideModal: (state) => {
logStateChange('Hiding modal', null, {
Expand All @@ -110,7 +113,11 @@ const uiSlice = createSlice({
});
state.modalOpen = false;
state.modalType = null;
state.modalContent = '';
},
setModalContent: (state, action) => {
state.modalContent = action.payload;
},
toggleVerbose: (state) => {
const newVerboseState = !state.verboseMode;
logStateChange('Toggling verbose mode', {
Expand All @@ -124,7 +131,7 @@ const uiSlice = createSlice({
},
});

export const {setTheme, showModal, hideModal, toggleVerbose, setActiveTab} = uiSlice.actions;
export const {setTheme, showModal, hideModal, toggleVerbose, setActiveTab, setModalContent} = uiSlice.actions;
logStateChange('Initialized slice', null, null, initialState);

export default uiSlice.reducer;
6 changes: 3 additions & 3 deletions webui/src/main/resources/application/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "/static/css/main.32ca5a31.css",
"main.js": "/static/js/main.efe59532.js",
"main.js": "/static/js/main.45e62201.js",
"static/js/9017.98ad007d.chunk.js": "/static/js/9017.98ad007d.chunk.js",
"static/js/5536.9c75127e.chunk.js": "/static/js/5536.9c75127e.chunk.js",
"static/js/7035.2bce51c5.chunk.js": "/static/js/7035.2bce51c5.chunk.js",
Expand Down Expand Up @@ -73,7 +73,7 @@
"static/js/5195.756798f5.chunk.js": "/static/js/5195.756798f5.chunk.js",
"index.html": "/index.html",
"main.32ca5a31.css.map": "/static/css/main.32ca5a31.css.map",
"main.efe59532.js.map": "/static/js/main.efe59532.js.map",
"main.45e62201.js.map": "/static/js/main.45e62201.js.map",
"9017.98ad007d.chunk.js.map": "/static/js/9017.98ad007d.chunk.js.map",
"5536.9c75127e.chunk.js.map": "/static/js/5536.9c75127e.chunk.js.map",
"7035.2bce51c5.chunk.js.map": "/static/js/7035.2bce51c5.chunk.js.map",
Expand Down Expand Up @@ -141,6 +141,6 @@
},
"entrypoints": [
"static/css/main.32ca5a31.css",
"static/js/main.efe59532.js"
"static/js/main.45e62201.js"
]
}
20 changes: 19 additions & 1 deletion webui/src/main/resources/application/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.efe59532.js"></script><link href="/static/css/main.32ca5a31.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link rel="icon" href="favicon.ico"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="theme-color" content="#000000"/>
<meta name="description" content="Web site created using create-react-app"/>
<link rel="apple-touch-icon" href="logo192.png"/>
<link rel="manifest" href="manifest.json"/>
<title>React App</title>
<script defer="defer" src="static/js/main.45e62201.js"></script>
<link href="static/css/main.32ca5a31.css" rel="stylesheet">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
649 changes: 649 additions & 0 deletions webui/src/main/resources/application/static/js/main.1331d5d1.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*!
* Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
* Copyright 2024 Fonticons, Inc.
*/

/*! @license DOMPurify 3.2.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.2/LICENSE */

/*! Bundled license information:

js-yaml/dist/js-yaml.mjs:
(*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT *)
*/

/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* use-sync-external-store-with-selector.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* Prism: Lightweight, robust, elegant syntax highlighting
*
* @license MIT <https://opensource.org/licenses/MIT>
* @author Lea Verou <https://lea.verou.me>
* @namespace
* @public
*/

Large diffs are not rendered by default.

648 changes: 648 additions & 0 deletions webui/src/main/resources/application/static/js/main.2003a3c3.js

Large diffs are not rendered by default.

Loading

0 comments on commit f8e0705

Please sign in to comment.