xlorfx commited on
Commit
8f46c7d
·
verified ·
1 Parent(s): d2e9521

Delete static/js/main.js

Browse files
Files changed (1) hide show
  1. static/js/main.js +0 -164
static/js/main.js DELETED
@@ -1,164 +0,0 @@
1
- document.addEventListener('DOMContentLoaded', () => {
2
- // Elementos da UI
3
- const contentDiv = document.getElementById('content');
4
- const loadingIndicator = `
5
- <div class="text-center py-8">
6
- <div class="inline-block animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-purple-600"></div>
7
- <p class="mt-2">Carregando...</p>
8
- </div>
9
- `;
10
-
11
- // Estado da aplicação
12
- let authToken = localStorage.getItem('authToken');
13
- let currentUser = null;
14
-
15
- // Rotas simples
16
- const routes = {
17
- '/': homePage,
18
- '/login': loginPage,
19
- '/goals': goalsPage
20
- };
21
-
22
- // Gerenciador de rotas
23
- function router() {
24
- contentDiv.innerHTML = loadingIndicator;
25
- const path = window.location.pathname;
26
- const routeHandler = routes[path] || notFoundPage;
27
- routeHandler();
28
- }
29
-
30
- // Páginas
31
- async function homePage() {
32
- if (!authToken) {
33
- window.location.pathname = '/login';
34
- return;
35
- }
36
-
37
- contentDiv.innerHTML = `
38
- <div class="bg-white rounded-lg shadow p-6">
39
- <h2 class="text-xl font-semibold mb-4">Bem-vindo ao GoalMaster AI</h2>
40
- <p class="mb-4">Crie e gerencie suas metas com ajuda da inteligência artificial.</p>
41
- <a href="/goals" class="btn-primary inline-block">Ver Minhas Metas</a>
42
- </div>
43
- `;
44
- }
45
-
46
- function loginPage() {
47
- contentDiv.innerHTML = `
48
- <div class="max-w-md mx-auto bg-white rounded-lg shadow p-6">
49
- <h2 class="text-xl font-semibold mb-4">Login</h2>
50
- <form id="loginForm" class="space-y-4">
51
- <div>
52
- <label class="block text-sm font-medium mb-1">Usuário</label>
53
- <input type="text" id="username" class="input-field" required>
54
- </div>
55
- <div>
56
- <label class="block text-sm font-medium mb-1">Senha</label>
57
- <input type="password" id="password" class="input-field" required>
58
- </div>
59
- <button type="submit" class="btn-primary w-full">Entrar</button>
60
- </form>
61
- </div>
62
- `;
63
-
64
- document.getElementById('loginForm').addEventListener('submit', async (e) => {
65
- e.preventDefault();
66
- const username = document.getElementById('username').value;
67
- const password = document.getElementById('password').value;
68
-
69
- try {
70
- const response = await fetch('/token', {
71
- method: 'POST',
72
- headers: {
73
- 'Content-Type': 'application/x-www-form-urlencoded',
74
- },
75
- body: new URLSearchParams({
76
- username,
77
- password,
78
- grant_type: 'password'
79
- })
80
- });
81
-
82
- if (!response.ok) throw new Error('Login falhou');
83
-
84
- const data = await response.json();
85
- authToken = data.access_token;
86
- localStorage.setItem('authToken', authToken);
87
- window.location.pathname = '/';
88
- } catch (error) {
89
- alert('Usuário ou senha incorretos');
90
- }
91
- });
92
- }
93
-
94
- async function goalsPage() {
95
- if (!authToken) {
96
- window.location.pathname = '/login';
97
- return;
98
- }
99
-
100
- contentDiv.innerHTML = loadingIndicator;
101
-
102
- try {
103
- const response = await fetch('/api/goals', {
104
- headers: {
105
- 'Authorization': `Bearer ${authToken}`
106
- }
107
- });
108
-
109
- if (!response.ok) throw new Error('Falha ao carregar metas');
110
-
111
- const goals = await response.json();
112
-
113
- contentDiv.innerHTML = `
114
- <div class="bg-white rounded-lg shadow p-6">
115
- <div class="flex justify-between items-center mb-6">
116
- <h2 class="text-xl font-semibold">Minhas Metas</h2>
117
- <button id="newGoalBtn" class="btn-primary">Nova Meta</button>
118
- </div>
119
- <div id="goalsList" class="space-y-4"></div>
120
- </div>
121
- `;
122
-
123
- const goalsList = document.getElementById('goalsList');
124
- goals.forEach(goal => {
125
- goalsList.innerHTML += `
126
- <div class="border rounded-lg p-4">
127
- <h3 class="font-medium">${goal.title}</h3>
128
- <p class="text-sm text-gray-600 mt-1">${goal.category}</p>
129
- </div>
130
- `;
131
- });
132
-
133
- document.getElementById('newGoalBtn').addEventListener('click', () => {
134
- // Implementar criação de nova meta
135
- alert('Funcionalidade de nova meta será implementada aqui');
136
- });
137
- } catch (error) {
138
- contentDiv.innerHTML = `
139
- <div class="bg-red-50 border-l-4 border-red-500 p-4 text-red-700">
140
- <p>Erro ao carregar metas: ${error.message}</p>
141
- </div>
142
- `;
143
- }
144
- }
145
-
146
- function notFoundPage() {
147
- contentDiv.innerHTML = `
148
- <div class="text-center py-8">
149
- <h2 class="text-xl font-semibold mb-2">Página não encontrada</h2>
150
- <a href="/" class="text-purple-600 hover:underline">Voltar para a página inicial</a>
151
- </div>
152
- `;
153
- }
154
-
155
- // Inicialização
156
- if (!authToken && window.location.pathname !== '/login') {
157
- window.location.pathname = '/login';
158
- } else {
159
- router();
160
- }
161
-
162
- // Navegação
163
- window.addEventListener('popstate', router);
164
- });