Skip to content

Commit d8756ee

Browse files
authored
Merge pull request #10 from LexaFrontDev/dev
feat(frontend): remove cache system, refactor pages, and add Tailwind…
2 parents 5609898 + ebabf11 commit d8756ee

119 files changed

Lines changed: 3088 additions & 1199 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
APP_ENV=prod
2-
APP_SECRET=25aeff0645dafb0ce3dc54218fd03bed
2+
APP_SECRET=
33

4-
DB_USER=root
5-
DB_PASS=
6-
DB_HOST=127.0.0.1
4+
DB_USER=your-database_user_name
5+
DB_PASS=your-database_password
6+
DB_HOST=your-database_host
77
DB_NAME=Time
88

99
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
@@ -20,6 +20,12 @@ MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"
2020
###> lexik/jwt-authentication-bundle ###
2121
JWT_PRIVATE_KEY_PATH=%kernel.project_dir%/config/jwt/private.pem
2222
JWT_PUBLIC_KEY_PATH=%kernel.project_dir%/config/jwt/public.pem
23-
JWT_PASSPHRASE=e357a5e49f1839042101695a96c07c9edfdf4939d4e91b1368d5c177153a71bc
23+
JWT_PASSPHRASE=
2424
###< lexik/jwt-authentication-bundle ###
2525

26+
VITE_CACHE_DB_NAME=
27+
VITE_CACHE_STORE_NAME=
28+
VITE_GOOGLE_CLIENT_ID=
29+
VITE_GOOGLE_REDIRECT_URI=
30+
VITE_PUSH_PUBLIC_KEY=
31+
VITE_PUSH_PRIVATE_KEY=

.env.dev

Lines changed: 0 additions & 25 deletions
This file was deleted.

.env.test

Lines changed: 0 additions & 8 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
###> symfony/framework-bundle ###
3+
package-lock.json
34
.env
45
.env.dev
56
.env.test
@@ -37,5 +38,4 @@ phpstan.neon
3738
###> friendsofphp/php-cs-fixer ###
3839
/.php-cs-fixer.php
3940
/.php-cs-fixer.cache
40-
package-lock.json
4141
###< friendsofphp/php-cs-fixer ###

assets/react/Router.tsx

Lines changed: 108 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import Habits_page from "./pages/Habits/HabitsPage";
88
import TasksPage from "./pages/Tasks/TasksPage";
99
//@ts-ignore
1010
import MatricPage from "./pages/MatricPage/MatricPage";
11-
import Premium from "./pages/main/pages/Premium";
1211
import PremiumPage from "./pages/main/pages/Premium";
1312
import Lending from "./pages/main/pages/Main";
1413
import LoginPage from "./pages/AuthPages/Login";
1514
import RegisterPage from "./pages/AuthPages/Register";
16-
import {AuthCheck} from "./ui/props/Auth/AuthCheck";
15+
import { AuthCheck } from "./ui/props/Auth/AuthCheck";
1716
import HabitCalendar from "./pages/Statistic/StatisticPage";
1817

1918
const RouterDom = () => {
20-
const [isAuthenticated, setIsAuthenticated] = useState<boolean|null>(null);
19+
const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
2120
const location = useLocation();
2221
const navigate = useNavigate();
2322

23+
// Сохраняем последнюю защищённую страницу
2424
useEffect(() => {
2525
const allowedPages = [
2626
'/tasks',
@@ -30,92 +30,131 @@ const RouterDom = () => {
3030
'/profile',
3131
'/profile/statistics'
3232
];
33-
3433
if (allowedPages.includes(location.pathname.toLowerCase())) {
3534
localStorage.setItem('last_page', location.pathname);
3635
}
3736
}, [location.pathname]);
3837

38+
3939
useEffect(() => {
4040
const checkAuth = async () => {
4141
try {
4242
const res = await fetch('/api/auth/check');
4343
const ok = res.ok;
4444
setIsAuthenticated(ok);
4545

46+
if(ok){
47+
console.log('Зов пениса');
48+
subscribePush();
49+
}
50+
4651
if (ok && location.pathname === '/') {
47-
const lastPage = localStorage.getItem('last_page') || '/Tasks';
52+
const lastPage = localStorage.getItem('last_page') || '/tasks';
4853
navigate(lastPage, { replace: true });
4954
}
55+
56+
const protectedPages = [
57+
'/tasks',
58+
'/habits',
59+
'/matric',
60+
'/pomodoro',
61+
'/profile',
62+
'/profile/statistics',
63+
'/premium'
64+
];
65+
if (!ok && protectedPages.includes(location.pathname.toLowerCase())) {
66+
navigate('/users/login', { replace: true });
67+
}
68+
5069
} catch {
5170
setIsAuthenticated(false);
71+
if (!['/users/login', '/users/register'].includes(location.pathname.toLowerCase())) {
72+
navigate('/users/login', { replace: true });
73+
}
5274
}
5375
};
5476
checkAuth();
55-
}, []);
77+
}, [location.pathname, navigate]);
5678

57-
if (isAuthenticated === null) return <Loading />;
5879

59-
return (
60-
<Routes>
61-
<Route path="/" element={<Lending />} />
6280

63-
<Route
64-
path="/profile"
65-
element={
66-
<AuthCheck isAuthenticated={isAuthenticated}>
67-
<Profile />
68-
</AuthCheck>
69-
}
70-
/>
71-
72-
<Route
73-
path="/pomodoro"
74-
element={
75-
<AuthCheck isAuthenticated={isAuthenticated}>
76-
<Pomodoro />
77-
</AuthCheck>
78-
}
79-
/>
80-
81-
<Route
82-
path="/habits"
83-
element={
84-
<AuthCheck isAuthenticated={isAuthenticated}>
85-
<Habits_page />
86-
</AuthCheck>
87-
}
88-
/>
8981

90-
<Route path="/users/register" element={<RegisterPage />} />
91-
<Route path="/users/login" element={<LoginPage />} />
9282

93-
<Route
94-
path="/tasks"
95-
element={
96-
<AuthCheck isAuthenticated={isAuthenticated}>
97-
<TasksPage />
98-
</AuthCheck>
99-
}
100-
/>
83+
const getPlatform = () => {
84+
const ua = navigator.userAgent;
10185

86+
let os = 'Unknown OS';
87+
if (/Windows NT/.test(ua)) os = 'Windows';
88+
else if (/Macintosh/.test(ua)) os = 'Mac';
89+
else if (/Android/.test(ua)) os = 'Android';
90+
else if (/iPhone|iPad|iPod/.test(ua)) os = 'iOS';
91+
else if (/Linux/.test(ua)) os = 'Linux';
10292

93+
let browser = 'Unknown Browser';
94+
if (/Chrome/.test(ua) && /Mobile/.test(ua)) browser = 'Chrome Mobile';
95+
else if (/Chrome/.test(ua)) browser = 'Chrome';
96+
else if (/Firefox/.test(ua)) browser = 'Firefox';
97+
else if (/Safari/.test(ua) && !/Chrome/.test(ua)) browser = 'Safari';
98+
else if (/Edg/.test(ua)) browser = 'Edge';
99+
else if (/OPR/.test(ua)) browser = 'Opera';
103100

104-
<Route
105-
path="/premium"
106-
element={
107-
<PremiumPage isAuthenticated={isAuthenticated} />
108-
}
109-
/>
110-
111-
<Route
112-
path="/profile/statistics"
113-
element={
114-
<AuthCheck isAuthenticated={isAuthenticated}>
115-
<HabitCalendar />
116-
</AuthCheck>
117-
}
118-
/>
101+
return `${browser}_${os}`;
102+
};
103+
104+
105+
106+
const subscribePush = async () => {
107+
if ('serviceWorker' in navigator) {
108+
navigator.serviceWorker.register('/serviceWorker/ServiceWorker.js')
109+
.then(registration => console.log('Service Worker зарегистрирован:', registration))
110+
.catch(err => console.error('Не удалось зарегистрировать Service Worker:', err));
111+
}
112+
113+
try {
114+
console.log('Дошлм епта')
115+
const registration = await navigator.serviceWorker.ready;
116+
const subscription = await registration.pushManager.subscribe({
117+
userVisibleOnly: true,
118+
applicationServerKey: urlBase64ToUint8Array(import.meta.env.VITE_PUSH_PUBLIC_KEY)
119+
});
120+
121+
const pushData = {
122+
platform: getPlatform(),
123+
endpoint: subscription.endpoint,
124+
keys: subscription.toJSON().keys
125+
};
126+
127+
console.log(pushData);
128+
129+
130+
await fetch('/api/save/subscription/web', {
131+
method: 'POST',
132+
headers: {
133+
'Content-Type': 'application/json',
134+
'Authorization': `Bearer ${localStorage.getItem('jwt')}`
135+
},
136+
body: JSON.stringify(pushData)
137+
});
138+
} catch (err) {
139+
console.error('Не удалось подписать на пуши:', err);
140+
}
141+
};
142+
143+
144+
if (isAuthenticated === null) return <Loading />;
145+
146+
return (
147+
<Routes>
148+
<Route path="/" element={<Lending />} />
149+
<Route path="/profile" element={<AuthCheck isAuthenticated={isAuthenticated}><Profile /></AuthCheck>} />
150+
<Route path="/pomodoro" element={<AuthCheck isAuthenticated={isAuthenticated}><Pomodoro /></AuthCheck>} />
151+
<Route path="/habits" element={<AuthCheck isAuthenticated={isAuthenticated}><Habits_page /></AuthCheck>} />
152+
<Route path="/tasks" element={<AuthCheck isAuthenticated={isAuthenticated}><TasksPage /></AuthCheck>} />
153+
<Route path="/profile/statistics" element={<AuthCheck isAuthenticated={isAuthenticated}><HabitCalendar /></AuthCheck>} />
154+
<Route path="/matric" element={<AuthCheck isAuthenticated={isAuthenticated}><MatricPage /></AuthCheck>} />
155+
<Route path="/premium" element={<AuthCheck isAuthenticated={isAuthenticated}><PremiumPage isAuthenticated={isAuthenticated} /></AuthCheck>} />
156+
<Route path="/users/register" element={<RegisterPage />} />
157+
<Route path="/users/login" element={<LoginPage />} />
119158
</Routes>
120159
);
121160
};
@@ -127,3 +166,11 @@ const WrappedRouterDom = () => (
127166
);
128167

129168
export default WrappedRouterDom;
169+
170+
171+
function urlBase64ToUint8Array(base64String: string) {
172+
const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
173+
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
174+
const rawData = atob(base64);
175+
return new Uint8Array([...rawData].map(c => c.charCodeAt(0)));
176+
}

0 commit comments

Comments
 (0)