generated from fahricansecer/boilerplate-fe
main
Some checks failed
UI Deploy (Next-Auth Support) 🎨 / build-and-deploy (push) Has been cancelled
Some checks failed
UI Deploy (Next-Auth Support) 🎨 / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -114,11 +114,23 @@ export default function TrendsPage() {
|
|||||||
type: trendsArray.length > 0 ? "success" : "info"
|
type: trendsArray.length > 0 ? "success" : "info"
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Failed to scan trends');
|
let errorMsg = 'Failed to scan trends';
|
||||||
|
const errorText = await res.text();
|
||||||
|
try {
|
||||||
|
const errorData = JSON.parse(errorText);
|
||||||
|
errorMsg = errorData.message || errorData.error || errorMsg;
|
||||||
|
} catch (e) {
|
||||||
|
if (errorText) errorMsg = errorText;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
throw new Error(errorMsg);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
console.error('Scan error:', error);
|
console.error('Scan error:', error);
|
||||||
toaster.create({ title: "Failed to scan trends", type: "error" });
|
toaster.create({
|
||||||
|
title: "Tarama Başarısız",
|
||||||
|
description: error.message || "Bilinmeyen bir hata oluştu.",
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setIsScanning(false);
|
setIsScanning(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,27 +153,27 @@ export function GeneratedContentResult({ bundle, masterContentId, onReset }: Pro
|
|||||||
throw new Error(masterData.message || 'Failed to fetch master content from backend');
|
throw new Error(masterData.message || 'Failed to fetch master content from backend');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the content record for this platform
|
|
||||||
const contents = masterData.contents || masterData.data?.contents || [];
|
const contents = masterData.contents || masterData.data?.contents || [];
|
||||||
|
|
||||||
const platformContent = contents.find((c: any) => {
|
const platformContent = contents.find((c: any) => {
|
||||||
const type = c.type?.toLowerCase() || '';
|
const type = (c.type || '').toLowerCase();
|
||||||
const pName = platformName.toLowerCase();
|
const pName = platformName.toLowerCase();
|
||||||
const title = c.title?.toLowerCase() || '';
|
const title = (c.title || '').toLowerCase();
|
||||||
|
|
||||||
// Match perfectly by title suffix (e.g., "Topic - medium")
|
// Priority 1: Match specifically by title suffix (e.g., "Topic - Medium")
|
||||||
if (title.endsWith(`- ${pName}`)) return true;
|
if (title.endsWith(`- ${pName}`)) return true;
|
||||||
if (title.includes(pName)) return true;
|
|
||||||
|
|
||||||
// Match medium to blog since backend saves medium as BLOG type
|
// Priority 2: Match medium to blog since backend saves medium as BLOG type
|
||||||
if (pName === 'medium' && type === 'blog') return true;
|
if (pName === 'medium' && (type === 'blog' || type === 'medium')) return true;
|
||||||
|
if (pName === 'blog' && (type === 'blog' || type === 'medium')) return true;
|
||||||
|
|
||||||
|
// Priority 3: Direct type match
|
||||||
return type === pName;
|
return type === pName;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!platformContent) {
|
if (!platformContent) {
|
||||||
console.error(`Save failed. platformName: ${platformName}, contents found: ${contents.length}`);
|
console.error(`Save failed. platformName: ${platformName}, contents found:`, contents);
|
||||||
throw new Error(`No saved content found for ${platformName}`);
|
throw new Error(`Kayıtlı içerik bulunamadı: ${platformName}. Lütfen sayfayı yenileyip tekrar deneyin.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the content
|
// Update the content
|
||||||
@@ -184,11 +184,17 @@ export function GeneratedContentResult({ bundle, masterContentId, onReset }: Pro
|
|||||||
|
|
||||||
const updateRes = await fetch(`/api/backend/content/${platformContent.id}`, {
|
const updateRes = await fetch(`/api/backend/content/${platformContent.id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers,
|
headers: {
|
||||||
|
...headers,
|
||||||
|
'Authorization': `Bearer ${session?.accessToken}`
|
||||||
|
},
|
||||||
body: JSON.stringify(updatePayload),
|
body: JSON.stringify(updatePayload),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!updateRes.ok) throw new Error('Failed to update content');
|
if (!updateRes.ok) {
|
||||||
|
const errData = await updateRes.json().catch(() => ({}));
|
||||||
|
throw new Error(errData.message || 'İçerik güncellenirken bir hata oluştu.');
|
||||||
|
}
|
||||||
|
|
||||||
toaster.create({
|
toaster.create({
|
||||||
title: "Saved!",
|
title: "Saved!",
|
||||||
@@ -333,24 +339,31 @@ export function GeneratedContentResult({ bundle, masterContentId, onReset }: Pro
|
|||||||
|
|
||||||
const contents = masterData.contents || masterData.data?.contents || [];
|
const contents = masterData.contents || masterData.data?.contents || [];
|
||||||
const platformContent = contents.find((c: any) => {
|
const platformContent = contents.find((c: any) => {
|
||||||
const type = c.type?.toLowerCase() || '';
|
const type = (c.type || '').toLowerCase();
|
||||||
const pName = platformName.toLowerCase();
|
const pName = platformName.toLowerCase();
|
||||||
const title = c.title?.toLowerCase() || '';
|
const title = (c.title || '').toLowerCase();
|
||||||
|
|
||||||
if (title.endsWith(`- ${pName}`)) return true;
|
if (title.endsWith(`- ${pName}`)) return true;
|
||||||
if (pName === 'medium' && type === 'blog') return true;
|
if (pName === 'medium' && (type === 'blog' || type === 'medium')) return true;
|
||||||
|
if (pName === 'blog' && (type === 'blog' || type === 'medium')) return true;
|
||||||
return type === pName;
|
return type === pName;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (platformContent) {
|
if (platformContent) {
|
||||||
await fetch(`/api/backend/content/${platformContent.id}`, {
|
const saveRes = await fetch(`/api/backend/content/${platformContent.id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers,
|
headers: {
|
||||||
|
...headers,
|
||||||
|
'Authorization': `Bearer ${session?.accessToken}`
|
||||||
|
},
|
||||||
body: JSON.stringify({ imageUrl }),
|
body: JSON.stringify({ imageUrl }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!saveRes.ok) throw new Error('Görsel güncellenirken hata oluştu.');
|
||||||
|
|
||||||
toaster.create({
|
toaster.create({
|
||||||
title: "Image Saved",
|
title: "Görsel Kaydedildi",
|
||||||
description: "Content image updated successfully.",
|
description: "İçerik görseli başarıyla güncellendi.",
|
||||||
type: "success",
|
type: "success",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user