refactor: güncellenmiş profil çerezi ile sonuç sayfası yönlendirmeleri
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
Profil çerezinin SSR'da kullanılmasını sağlayarak, sonuç sayfasındaki yönlendirmeleri güncelledik. Artık profil bilgileri URL parametreleri yerine çerezden alınarak işleniyor. Ayrıca, profil çerezi olmayan kullanıcılar için yönlendirme mantığı iyileştirildi. Çeşitli bileşenlerdeki URL oluşturma fonksiyonları güncellenerek, profil bilgileri çerezden okunacak şekilde düzenlendi. Bu değişiklikler, kullanıcı deneyimini artırmayı ve daha tutarlı bir veri akışı sağlamayı hedefliyor.
This commit is contained in:
@@ -123,9 +123,7 @@ export function CtaSiraForm({ baslik }: { baslik?: string }) {
|
||||
const yeniProfil = { sira, tur, secimler };
|
||||
tercihProfiliYaz(yeniProfil);
|
||||
setAcik(false);
|
||||
router.push(
|
||||
sonucHref(yeniProfil, girisli ? { sihirbaz: "1" } : { hazir: "1" }),
|
||||
);
|
||||
router.push(sonucHref(girisli ? { sihirbaz: "1" } : { hazir: "1" }));
|
||||
}
|
||||
|
||||
function acikDegisti(v: boolean) {
|
||||
@@ -150,7 +148,7 @@ export function CtaSiraForm({ baslik }: { baslik?: string }) {
|
||||
programların hazır.
|
||||
</p>
|
||||
<Link
|
||||
href={sonucHref(profil)}
|
||||
href={sonucHref()}
|
||||
className="mt-4 inline-flex h-12 items-center justify-center gap-2 rounded-full bg-orange-500 px-7 text-sm font-semibold text-white transition-colors duration-200 hover:bg-orange-600"
|
||||
>
|
||||
Sıralamana uygun programları gör
|
||||
|
||||
@@ -100,9 +100,7 @@ export function HeroForm() {
|
||||
const profil = { sira, tur, secimler };
|
||||
tercihProfiliYaz(profil);
|
||||
setModalAcik(false);
|
||||
router.push(
|
||||
sonucHref(profil, girisli ? { sihirbaz: "1" } : { hazir: "1" }),
|
||||
);
|
||||
router.push(sonucHref(girisli ? { sihirbaz: "1" } : { hazir: "1" }));
|
||||
}
|
||||
|
||||
// Kayıtlı profil varsa sihirbazı atla, doğrudan sonuç sayfasına götür.
|
||||
@@ -116,7 +114,7 @@ export function HeroForm() {
|
||||
size="lg"
|
||||
className="w-full cursor-pointer bg-orange-500 text-white transition-colors duration-200 hover:bg-orange-600 sm:w-auto"
|
||||
>
|
||||
<Link href={sonucHref(kayitliProfil)}>
|
||||
<Link href={sonucHref()}>
|
||||
Üniversitelere göz at
|
||||
<ArrowRight className="size-4" aria-hidden />
|
||||
</Link>
|
||||
|
||||
@@ -110,6 +110,9 @@ export function SihirbazAdimlar({
|
||||
// eşleşme için iki taraf da normalizeIlAdi'dan geçirilir.
|
||||
const [ilArama, setIlArama] = useState("");
|
||||
const ilAramaNorm = normalizeIlAdi(ilArama.trim());
|
||||
// 81 çip ilk bakışta boğucu; varsayılan görünüm ilk 10 il + "+N il daha"
|
||||
// rozeti. Arama açıkken kırpma yok (arama zaten görünümü daraltıyor).
|
||||
const [tumIllerAcik, setTumIllerAcik] = useState(false);
|
||||
const gorunenTurkiyeIlleri = useMemo(
|
||||
() =>
|
||||
ilAramaNorm
|
||||
@@ -119,6 +122,14 @@ export function SihirbazAdimlar({
|
||||
: turkiyeIlleri,
|
||||
[turkiyeIlleri, ilAramaNorm],
|
||||
);
|
||||
const IL_ON_IZLEME = 10;
|
||||
const ilListesiKirpik =
|
||||
!ilAramaNorm &&
|
||||
!tumIllerAcik &&
|
||||
gorunenTurkiyeIlleri.length > IL_ON_IZLEME;
|
||||
const listelenenTurkiyeIlleri = ilListesiKirpik
|
||||
? gorunenTurkiyeIlleri.slice(0, IL_ON_IZLEME)
|
||||
: gorunenTurkiyeIlleri;
|
||||
const gorunenDisIller = useMemo(
|
||||
() =>
|
||||
ilAramaNorm
|
||||
@@ -314,15 +325,16 @@ export function SihirbazAdimlar({
|
||||
|
||||
{/* Çipler birincil seçim yolu (haritadaki küçük iller mobilde
|
||||
güvenilir dokunma hedefi değil); iller seçili kategorilere göre
|
||||
süzülmüş, program sayısına göre sıralı listelenir. Penceresinde
|
||||
programı olan TÜM iller görünür (kırpma yok); arama yalnızca
|
||||
görünümü daraltır, seçimleri etkilemez. */}
|
||||
süzülmüş, program sayısına göre sıralı listelenir. Varsayılan
|
||||
görünüm ilk 10 il; kalanı "+N il daha" rozetiyle açılır. Arama
|
||||
yalnızca görünümü daraltır, seçimleri etkilemez ve kırpmayı
|
||||
devre dışı bırakır. */}
|
||||
<div
|
||||
className={`mt-3 flex max-h-56 flex-wrap gap-1.5 overflow-y-auto sm:max-h-none sm:overflow-visible ${
|
||||
facetYukleniyor ? "animate-pulse opacity-60" : ""
|
||||
}`}
|
||||
>
|
||||
{gorunenTurkiyeIlleri.map((i) => (
|
||||
{listelenenTurkiyeIlleri.map((i) => (
|
||||
<Cip
|
||||
key={i.il}
|
||||
kucuk
|
||||
@@ -333,6 +345,27 @@ export function SihirbazAdimlar({
|
||||
<span className="ml-1 text-[10px] opacity-70">{i.adet}</span>
|
||||
</Cip>
|
||||
))}
|
||||
{ilListesiKirpik ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setTumIllerAcik(true)}
|
||||
className="cursor-pointer rounded-full border border-dashed border-slate-300 bg-white px-2.5 py-1 text-xs font-medium text-slate-500 transition-colors duration-200 hover:border-slate-400 hover:bg-slate-50 hover:text-slate-700"
|
||||
>
|
||||
+{gorunenTurkiyeIlleri.length - IL_ON_IZLEME} il daha
|
||||
</button>
|
||||
) : null}
|
||||
{!ilListesiKirpik &&
|
||||
tumIllerAcik &&
|
||||
!ilAramaNorm &&
|
||||
gorunenTurkiyeIlleri.length > IL_ON_IZLEME ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setTumIllerAcik(false)}
|
||||
className="cursor-pointer rounded-full border border-dashed border-slate-300 bg-white px-2.5 py-1 text-xs font-medium text-slate-500 transition-colors duration-200 hover:border-slate-400 hover:bg-slate-50 hover:text-slate-700"
|
||||
>
|
||||
Daha az göster
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{ilAramaNorm &&
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"use client";
|
||||
|
||||
// /sonuc?sira= yokken: kayıtlı profil varsa oraya taşı; yoksa kapıyı aç.
|
||||
// Sıra bilgisi localStorage'daki TercihProfili ile tüm uygulamada ortak.
|
||||
// Profil çerezi yokken: localStorage'da kayıtlı profil varsa çereze taşıyıp
|
||||
// sayfayı tazele (URL değişmez); yoksa kapıyı aç. Sıra bilgisi localStorage'daki
|
||||
// TercihProfili ile tüm uygulamada ortak, sunucu tablosu çerezden okur.
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
@@ -9,7 +10,7 @@ import Link from "next/link";
|
||||
import { ArrowLeft, Trophy } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { PagePixelDivider } from "@/components/pixel-decor";
|
||||
import { sonucHref } from "@/features/sihirbaz/sihirbaz-sabitler";
|
||||
import { profilCerezineYaz } from "@/features/sihirbaz/sihirbaz-profil";
|
||||
import {
|
||||
sonucaGitIste,
|
||||
useProfilKapisi,
|
||||
@@ -20,9 +21,14 @@ export function SiraGerekli() {
|
||||
const { profil, profilYuklendi } = useProfilKapisi();
|
||||
|
||||
// "Yönleniyor" durumu ayrı state gerektirmez: profil varken aşağıdaki koşul
|
||||
// zaten bekleme ekranını gösteriyor; effect yalnızca yönlendirmeyi yapar.
|
||||
// zaten bekleme ekranını gösteriyor. Çerezi olmayan eski kullanıcı (profil
|
||||
// yalnızca localStorage'da) burada çereze taşınır; refresh sunucu tablosunu
|
||||
// aynı URL'de yeni çerezle render eder.
|
||||
useEffect(() => {
|
||||
if (profilYuklendi && profil) router.replace(sonucHref(profil));
|
||||
if (profilYuklendi && profil) {
|
||||
profilCerezineYaz(profil);
|
||||
router.refresh();
|
||||
}
|
||||
}, [profil, profilYuklendi, router]);
|
||||
|
||||
if (!profilYuklendi || profil) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Şema, doğrulama ve sabitler sihirbaz-sabitler.ts'te yaşar.
|
||||
|
||||
import {
|
||||
PROFIL_CEREZ_ADI,
|
||||
PROFIL_DEGISTI_EVENT,
|
||||
SIHIRBAZ_STORAGE_KEY,
|
||||
tercihProfiliDogrula,
|
||||
@@ -42,6 +43,24 @@ export function tercihProfiliOku(): TercihProfili | null {
|
||||
return profilCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Profilin sunucu aynası: /sonuc SSR'ı tabloyu bu çerezden filtreler
|
||||
* (bkz. PROFIL_CEREZ_ADI). localStorage'ı olup çerezi olmayan eski
|
||||
* kullanıcıların taşınması için SiraGerekli de bunu çağırır.
|
||||
*/
|
||||
export function profilCerezineYaz(profil: TercihProfili): void {
|
||||
if (typeof document === "undefined") return;
|
||||
const guvenli = window.location.protocol === "https:" ? "; secure" : "";
|
||||
document.cookie = `${PROFIL_CEREZ_ADI}=${encodeURIComponent(
|
||||
JSON.stringify(profil),
|
||||
)}; path=/; max-age=31536000; samesite=lax${guvenli}`;
|
||||
}
|
||||
|
||||
function profilCereziniSil(): void {
|
||||
if (typeof document === "undefined") return;
|
||||
document.cookie = `${PROFIL_CEREZ_ADI}=; path=/; max-age=0`;
|
||||
}
|
||||
|
||||
/** Ortak profili yazar; hero ve Yapay Zeka sihirbazıyla aynı anahtarı kullanır. */
|
||||
export function tercihProfiliYaz(profil: TercihProfili): void {
|
||||
if (typeof window === "undefined") return;
|
||||
@@ -50,6 +69,7 @@ export function tercihProfiliYaz(profil: TercihProfili): void {
|
||||
try {
|
||||
localStorage.setItem(SIHIRBAZ_STORAGE_KEY, JSON.stringify(dogru));
|
||||
} catch {}
|
||||
profilCerezineYaz(dogru);
|
||||
profilCache = dogru;
|
||||
profilDegistiginiYayinla();
|
||||
}
|
||||
@@ -60,6 +80,7 @@ export function tercihProfiliSil(): void {
|
||||
try {
|
||||
localStorage.removeItem(SIHIRBAZ_STORAGE_KEY);
|
||||
} catch {}
|
||||
profilCereziniSil();
|
||||
profilCache = null;
|
||||
profilDegistiginiYayinla();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,12 @@ export const PUAN_TURU_ETIKET: Record<string, string> = {
|
||||
// dönene kadar burada bekler.
|
||||
export const SIHIRBAZ_STORAGE_KEY = "kolaytercih.sihirbaz";
|
||||
|
||||
// Profilin sunucuya giden kopyası: /sonuc tablosu SSR'da bu çerezden
|
||||
// filtrelenir, URL'de sira/il/tip paramı taşınmaz. localStorage client
|
||||
// tarafındaki tek doğruluk kaynağı olmayı sürdürür; çerez onun aynasıdır
|
||||
// (tercihProfiliYaz/Sil ikisini birlikte günceller).
|
||||
export const PROFIL_CEREZ_ADI = "kolaytercih.profil";
|
||||
|
||||
// storage olayı yalnızca diğer sekmelerde tetiklenir; aynı sekmedeki
|
||||
// aboneler (ör. navbar sıralama rozeti) bu olayla haberdar edilir.
|
||||
export const PROFIL_DEGISTI_EVENT = "kolaytercih:profil-degisti";
|
||||
@@ -126,30 +132,27 @@ export function tercihProfiliDogrula(girdi: unknown): TercihProfili | null {
|
||||
return { sira, tur: p.tur, secimler };
|
||||
}
|
||||
|
||||
/**
|
||||
* Profildeki sıra/tur ile sonuç sayfası URL'i — tüm uygulama aynı sorguyu
|
||||
* kullanır. Profilde sihirbaz seçimleri varsa il + üniversite tipi de URL'e
|
||||
* yazılır: /sonuc'un ham tablosu SSR'da bu paramlarla filtrelenir (tek
|
||||
* doğruluk kaynağı URL; localStorage profili yalnızca URL'i üretir).
|
||||
*/
|
||||
export function sonucHref(
|
||||
profil: Pick<TercihProfili, "sira" | "tur"> & {
|
||||
secimler?: SihirbazSecimleri;
|
||||
},
|
||||
ekstra?: Record<string, string>,
|
||||
): string {
|
||||
const q = new URLSearchParams({
|
||||
sira: String(profil.sira),
|
||||
tur: profil.tur,
|
||||
});
|
||||
if (profil.secimler) {
|
||||
for (const il of profil.secimler.iller) q.append("il", il);
|
||||
if (profil.secimler.universiteTipi !== "farketmez") {
|
||||
q.set("tip", profil.secimler.universiteTipi);
|
||||
}
|
||||
/** /sonuc çerezindeki ham değeri güvenle profile çözer (SSR tarafı). */
|
||||
export function cerezdenTercihProfili(
|
||||
ham: string | undefined | null,
|
||||
): TercihProfili | null {
|
||||
if (!ham) return null;
|
||||
try {
|
||||
return tercihProfiliDogrula(JSON.parse(decodeURIComponent(ham)));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
for (const [k, v] of Object.entries(ekstra ?? {})) q.set(k, v);
|
||||
return `/sonuc?${q}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sonuç sayfası URL'i. Profil verisi (sıra/tür/il/tip) URL'de taşınmaz —
|
||||
* /sonuc'un ham tablosu SSR'da PROFIL_CEREZ_ADI çerezinden filtrelenir.
|
||||
* `ekstra` yalnızca tek seferlik akış bayrakları içindir (sihirbaz=1, hazir=1).
|
||||
*/
|
||||
export function sonucHref(ekstra?: Record<string, string>): string {
|
||||
const girdiler = Object.entries(ekstra ?? {});
|
||||
if (girdiler.length === 0) return "/sonuc";
|
||||
return `/sonuc?${new URLSearchParams(girdiler)}`;
|
||||
}
|
||||
|
||||
/** Prompt'a enjekte edilecek Türkçe özet. */
|
||||
|
||||
Reference in New Issue
Block a user