refactor: ts
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<!-- src/App.svelte -->
|
<!-- src/App.svelte -->
|
||||||
<script>
|
<script lang="ts">
|
||||||
import './app.css';
|
import './app.css';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { activeTab } from './stores/appStore';
|
import { activeTab } from './stores/appStore';
|
||||||
@@ -11,8 +11,7 @@
|
|||||||
import Terminal from './components/Terminal.svelte';
|
import Terminal from './components/Terminal.svelte';
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// Prevent context menu
|
const handleContextMenu = (event: MouseEvent) => event.preventDefault();
|
||||||
const handleContextMenu = (event) => event.preventDefault();
|
|
||||||
document.addEventListener('contextmenu', handleContextMenu);
|
document.addEventListener('contextmenu', handleContextMenu);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!-- src/components/Header.svelte -->
|
<!-- src/components/Header.svelte -->
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { isOnline } from '../stores/appStore';
|
import { isOnline } from '../stores/appStore';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!-- components/Overview.svelte -->
|
<!-- components/Overview.svelte -->
|
||||||
<script>
|
<script lang="ts">
|
||||||
import StatusPanel from './StatusPanel.svelte';
|
import StatusPanel from './StatusPanel.svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!-- components/Settings.svelte -->
|
<!-- components/Settings.svelte -->
|
||||||
<script>
|
<script lang="ts">
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="settings-content">
|
<div class="settings-content">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!-- src/components/StatusPanel.svelte -->
|
<!-- src/components/StatusPanel.svelte -->
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { status, uptime, qrCodesFound } from '../stores/appStore';
|
import { status, uptime, qrCodesFound } from '../stores/appStore';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<!-- src/components/Tabs.svelte -->
|
<!-- src/components/Tabs.svelte -->
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { activeTab, TABS } from '../stores/appStore';
|
import { activeTab, TABS } from '../stores/appStore';
|
||||||
|
import type { Tab } from '../stores/appStore';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="tabs-container">
|
<div class="tabs-container">
|
||||||
{#each TABS as tab}
|
{#each TABS as tab (tab.id)}
|
||||||
<button
|
<button
|
||||||
class="tab {$activeTab === tab.id ? 'active' : ''}"
|
class="tab {$activeTab === tab.id ? 'active' : ''}"
|
||||||
on:click={() => $activeTab = tab.id}
|
on:click={() => $activeTab = tab.id}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
<!-- src/components/Terminal.svelte -->
|
<!-- src/components/Terminal.svelte -->
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { terminalLines } from '../stores/appStore';
|
import { terminalLines } from '../stores/appStore';
|
||||||
import { onMount, onDestroy } from 'svelte';
|
import { onMount, onDestroy } from 'svelte';
|
||||||
|
|
||||||
let terminalRef;
|
let terminalRef: HTMLDivElement;
|
||||||
let isResizing = false;
|
let isResizing = false;
|
||||||
let startY, startHeight;
|
let startY: number;
|
||||||
|
let startHeight: number;
|
||||||
|
|
||||||
function handleMouseDown(e) {
|
function handleMouseDown(e: MouseEvent): void {
|
||||||
isResizing = true;
|
isResizing = true;
|
||||||
startY = e.clientY;
|
startY = e.clientY;
|
||||||
startHeight = parseInt(getComputedStyle(terminalRef).height, 10);
|
startHeight = parseInt(getComputedStyle(terminalRef).height, 10);
|
||||||
@@ -17,7 +18,7 @@
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseMove(e) {
|
function handleMouseMove(e: MouseEvent): void {
|
||||||
if (!isResizing) return;
|
if (!isResizing) return;
|
||||||
|
|
||||||
const height = startHeight - (e.clientY - startY);
|
const height = startHeight - (e.clientY - startY);
|
||||||
@@ -29,15 +30,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseUp() {
|
function handleMouseUp(): void {
|
||||||
isResizing = false;
|
isResizing = false;
|
||||||
document.removeEventListener('mousemove', handleMouseMove);
|
document.removeEventListener('mousemove', handleMouseMove);
|
||||||
document.removeEventListener('mouseup', handleMouseUp);
|
document.removeEventListener('mouseup', handleMouseUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollToBottom() {
|
function scrollToBottom(): void {
|
||||||
if (terminalRef) {
|
if (terminalRef) {
|
||||||
const content = terminalRef.querySelector('.terminal-content');
|
const content = terminalRef.querySelector('.terminal-content') as HTMLDivElement;
|
||||||
if (content) {
|
if (content) {
|
||||||
content.scrollTop = content.scrollHeight;
|
content.scrollTop = content.scrollHeight;
|
||||||
}
|
}
|
||||||
@@ -84,10 +85,10 @@
|
|||||||
|
|
||||||
.resize-handle {
|
.resize-handle {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 10;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
height: 4px;
|
height: 10px;
|
||||||
cursor: row-resize;
|
cursor: row-resize;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
@@ -95,6 +96,8 @@
|
|||||||
|
|
||||||
.resize-handle:hover {
|
.resize-handle:hover {
|
||||||
background-color: var(--accent-primary);
|
background-color: var(--accent-primary);
|
||||||
|
border-radius: 100px;
|
||||||
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.terminal-header {
|
.terminal-header {
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import { writable } from 'svelte/store';
|
|
||||||
|
|
||||||
// App state
|
|
||||||
export const activeTab = writable('overview');
|
|
||||||
export const status = writable('Looking for QR-codes');
|
|
||||||
export const uptime = writable('1h 12m 15s');
|
|
||||||
export const qrCodesFound = writable(12);
|
|
||||||
export const isOnline = writable(true);
|
|
||||||
export const terminalLines = writable([
|
|
||||||
'Window()',
|
|
||||||
'[Fx] INVOKE main.main.func1()',
|
|
||||||
'[Fx] BEFORE RUN provide: git.weirdcat.su/weirdcat/auto-attendance/internal/ui.NewBuilder()',
|
|
||||||
'[Fx] RUN provide: git.weirdcat.su/weirdcat/auto-attendance/internal/ui.NewBuilder() in 46.723905ms',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
export const TABS = [
|
|
||||||
{ id: 'overview', label: 'Overview' },
|
|
||||||
{ id: 'settings', label: 'Settings' }
|
|
||||||
];
|
|
||||||
23
frontend/src/stores/appStore.ts
Normal file
23
frontend/src/stores/appStore.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// ./stores/appStore.ts
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
|
export interface Tab {
|
||||||
|
id: 'overview' | 'settings';
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TABS: Tab[] = [
|
||||||
|
{ id: 'overview', label: 'Overview' },
|
||||||
|
{ id: 'settings', label: 'Settings' }
|
||||||
|
];
|
||||||
|
|
||||||
|
export const activeTab = writable<Tab['id']>('overview');
|
||||||
|
export const isOnline = writable<boolean>(false);
|
||||||
|
export const status = writable<string>('Stopped');
|
||||||
|
export const uptime = writable<string>('0s');
|
||||||
|
export const qrCodesFound = writable<number>(0);
|
||||||
|
export const terminalLines = writable<string[]>([
|
||||||
|
'Tea warming up...',
|
||||||
|
'Scanning QR-code...',
|
||||||
|
'Getting expelled...'
|
||||||
|
]);
|
||||||
Reference in New Issue
Block a user