Новые глобабальные правки

This commit is contained in:
Web-serfer 2026-04-18 21:07:30 +05:00
parent b5b31f8a88
commit 36a3d37ad3
8 changed files with 35 additions and 26 deletions

View file

@ -5,7 +5,9 @@ export default function CommentLock() {
onMount(() => {
const path = window.location.pathname;
setCurrentPath(`/auth/sign-in?redirect=${encodeURIComponent(path)}`);
const hash = window.location.hash;
const redirectTo = hash ? `${path}${hash}` : path;
setCurrentPath(`/auth/sign-in?redirect=${encodeURIComponent(redirectTo)}`);
});
return (
@ -23,7 +25,7 @@ export default function CommentLock() {
>
<div
class="w-20 h-20 mx-auto mb-6 rounded-full flex items-center justify-center"
style="background: linear-gradient(135deg, rgba(234, 194, 110, 0.2) 0%, rgba(234, 194, 110, 0.3) 100%);"
style="background: linear-gradient(135deg, rgba(37, 99, 235, 0.2) 0%, rgba(30, 64, 175, 0.3) 100%);"
>
<svg class="w-10 h-10 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/>
@ -36,7 +38,7 @@ export default function CommentLock() {
<a
href={currentPath()}
class="inline-flex items-center justify-center font-semibold transition-all duration-300 rounded-md cursor-pointer px-6 py-3 text-lg"
style="background: linear-gradient(to bottom, #eac26e, #ce9f40); color: white; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);"
style="background: linear-gradient(to bottom, #2563eb, #1e40af); color: white; box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);"
>
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1"/>
@ -48,7 +50,7 @@ export default function CommentLock() {
<a
href={`/auth/sign-up?redirect=${encodeURIComponent(window.location.pathname)}`}
class="font-medium hover:underline"
style="color: #ce9f40;"
style="color: #2563eb;"
>
Зарегистрироваться
</a>

View file

@ -1,12 +0,0 @@
---
import Comments from "./Comments";
import type { Props as BaseProps } from "../../../types/comments";
interface Props extends BaseProps {
postSlug: string;
}
const { postSlug } = Astro.props;
---
<Comments postSlug={postSlug} client:load />

View file

@ -1,7 +1,7 @@
import { createSignal, For, Show, onMount } from "solid-js";
import CommentLock from "./CommentLock";
import CommentForm from "./CommentForm";
import type { CommentWithReplies } from "../../types/comments";
import type { CommentWithReplies } from "../../../types/comments";
interface CommentsProps {
postSlug: string;

View file

@ -374,7 +374,8 @@ import { COMPANY } from "@constants";
localStorage.removeItem('auth_token');
localStorage.removeItem('user');
document.querySelector('.header-right')?.classList.remove('auth-active');
window.location.href = '/';
// Редирект на текущую страницу
window.location.href = window.location.pathname + window.location.search + window.location.hash;
});
// Добавляем класс для изменения порядка

View file

@ -1,11 +1,11 @@
import type { APIRoute } from 'astro';
import { pb } from '../../../lib/pb';
export const POST: APIRoute = async ({ request, cookies }) => {
export const POST: APIRoute = async ({ request, cookies, url }) => {
try {
const data = await request.json();
const { email, password } = data;
const { email, password, redirect } = data;
if (!email || !password) {
return new Response(JSON.stringify({
@ -36,6 +36,12 @@ export const POST: APIRoute = async ({ request, cookies }) => {
maxAge: 60 * 60 * 24 * 7,
});
// Определяем URL для редиректа
let redirectUrl = '/';
if (redirect) {
redirectUrl = redirect;
}
return new Response(JSON.stringify({
success: true,
token: authData.token,
@ -43,7 +49,8 @@ export const POST: APIRoute = async ({ request, cookies }) => {
id: authData.record.id,
name: authData.record.firstName,
email: authData.record.email,
}
},
redirect: redirectUrl
}), { status: 200 });
} catch (error: any) {

View file

@ -456,7 +456,11 @@ import { SITE_URL } from '@constants';
const response = await fetch('/api/auth/sign-in', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
body: JSON.stringify({
email,
password,
redirect: new URLSearchParams(window.location.search).get('redirect')
}),
});
const data = await response.json();
@ -469,8 +473,14 @@ import { SITE_URL } from '@constants';
// Сохраняем токен в куку для API
document.cookie = `pb_auth=${data.token}; path=/; max-age=${7 * 24 * 60 * 60}; SameSite=Lax`;
// Перенаправляем в личный кабинет
window.location.href = '/cabinet';
// Перенаправляем на указанный URL или в личный кабинет
const redirectUrl = data.redirect || '/cabinet';
// Если есть хэш с ID комментариев - добавляем его к URL
const hash = new URLSearchParams(window.location.search).get('hash');
const finalUrl = hash ? `${redirectUrl}#comments` : redirectUrl;
window.location.href = finalUrl;
} else if (data.error?.includes('подтверждён')) {
showError(emailInput, data.error);
} else if (data.error?.includes('пароль')) {

View file

@ -1,7 +1,7 @@
---
import ArticleLayout from '@layouts/ArticleLayout.astro';
import { SITE_URL } from '@constants';
import Comments from '@components/blog/comments/Comments.astro';
import Comments from '@components/blog/comments/Comments.tsx';
import RelatedPosts from '@components/blog/RelatedPosts.astro';
import ArticleTableOfContents from '@components/blog/ArticleTableOfContents.astro';
import { getPostBySlug, getPosts, getPostImageUrl, getPostVotesStats } from '@lib/pb';
@ -82,7 +82,7 @@ const heroImage = getPostImageUrl(post);
<!-- Система комментариев -->
<div class="comments-wrapper">
<Comments postSlug={post.slug} />
<Comments postSlug={post.slug} client:load />
</div>
<!-- Похожие статьи -->

View file

@ -15,6 +15,7 @@ export interface CommentRecord {
export interface UserRecord {
id: string;
firstName?: string;
name: string;
email: string;
avatar?: string;