minor bugfixes

This commit is contained in:
Hikmet 2023-12-12 15:23:30 +03:00
parent 4692487e1e
commit 6d82caeefd
8 changed files with 70 additions and 8 deletions

View File

@ -2,6 +2,7 @@ import Link from "next/link";
import styles from "./app_bar.module.scss";
import { MenuRounded } from "@mui/icons-material";
import { useState } from "react";
import { IndexPageTemplate } from "@/lib/types/website_page_templates/index_page_template";
export function AppBar({
home,

View File

@ -4,6 +4,7 @@ import { WelcomeSection } from "./welcome_section/welcome_section";
import { Footer } from "../footer";
import { ReactNode } from "react";
import { ThemeMetaDTO } from "@/lib/theme/theme_meta_dto";
import { IndexPageTemplate } from "@/lib/types/website_page_templates/index_page_template";
export function LandingPageView({
themePreviews,

View File

@ -1,3 +1,4 @@
import { IndexPageTemplate } from "@/lib/types/website_page_templates/index_page_template";
import styles from "./welcome_section.module.scss";
export function WelcomeSection({

View File

@ -2,19 +2,22 @@ import ITheme from "@/lib/theme/theme";
import { View } from "./view";
import { ViewModel } from "./view_model";
import { ReactNode } from "react";
import { IndexPageTemplate } from "@/lib/types/website_page_templates/index_page_template";
export default function ThemePage({
theme,
home,
adminTools,
pageTemplate,
}: {
theme: ITheme;
home: "/admin" | "/";
adminTools?: ReactNode;
pageTemplate: IndexPageTemplate;
}) {
return (
<ViewModel theme={theme}>
<View adminTools={adminTools} home={home} />
<View adminTools={adminTools} home={home} pageTemplate={pageTemplate} />
</ViewModel>
);
}

View File

@ -9,6 +9,7 @@ import { Footer } from "@/features/footer";
import { TabBar } from "./tab_bar";
import { ReactNode } from "react";
import dynamic from "next/dynamic";
import { IndexPageTemplate } from "@/lib/types/website_page_templates/index_page_template";
const ActivityDialog = dynamic(() => import("./activity_dialog"), {
ssr: false,
@ -17,9 +18,11 @@ const ActivityDialog = dynamic(() => import("./activity_dialog"), {
export function View({
home,
adminTools,
pageTemplate,
}: {
home: "/admin" | "/";
adminTools?: ReactNode;
pageTemplate: IndexPageTemplate;
}) {
const {
isActivityDialogOpen,
@ -42,7 +45,7 @@ export function View({
key="image"
/>
</Head>
<AppBar home={home} />
<AppBar home={home} pageTemplate={pageTemplate} />
<div className={styles["main"]}>
<Banner />
<TabBar />

View File

@ -1,14 +1,17 @@
import { LandingPageView } from "@/features/landing_page_view";
import { DynamoDBWebsitePageTemplateRepository } from "@/lib/repositories/website_page_template/dynamodb_website_page_template_repository";
import ThemeAdminService from "@/lib/services/theme/theme_admin_service";
import ThemeApiService from "@/lib/services/theme/theme_api_service";
import { defaultTheme } from "@/lib/theme/default_theme";
import { ThemeMetaDTO } from "@/lib/theme/theme_meta_dto";
import { IndexPageTemplate } from "@/lib/types/website_page_templates/index_page_template";
import Head from "next/head";
import { useEffect, useRef, useState } from "react";
export default function AdminPage() {
const adminService = useRef(new ThemeAdminService());
const [themeMetas, setThemeMetas] = useState<ThemeMetaDTO[]>();
const [pageTemplate, setPageTemplate] = useState<IndexPageTemplate>();
const [stalling, setStalling] = useState(false);
const fetchThemeMetas = async () => {
@ -21,8 +24,18 @@ export default function AdminPage() {
}
};
const fetchPageTemplate = async () => {
const dynamodbWebsiteTemplateRepo =
new DynamoDBWebsitePageTemplateRepository();
const res = await dynamodbWebsiteTemplateRepo.getIndexPageTemplate();
if (res.status === "success" && res.data) {
setPageTemplate(res.data);
}
};
useEffect(() => {
fetchThemeMetas();
fetchPageTemplate();
}, []);
const createTheme = async () => {
@ -32,7 +45,7 @@ export default function AdminPage() {
setStalling(false);
};
if (!themeMetas) {
if (!themeMetas || !pageTemplate) {
return (
<div className="admin-waiting-room">
<h1>Merhaba Admin!</h1>
@ -48,6 +61,7 @@ export default function AdminPage() {
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<LandingPageView
pageTemplate={pageTemplate}
home="/admin"
themePreviews={themeMetas}
createNewThemeButton={

View File

@ -4,6 +4,8 @@ import { usePathname } from "next/navigation";
import dynamic from "next/dynamic";
import ThemeAdminService from "@/lib/services/theme/theme_admin_service";
import ITheme from "@/lib/theme/theme";
import { DynamoDBWebsitePageTemplateRepository } from "@/lib/repositories/website_page_template/dynamodb_website_page_template_repository";
import { IndexPageTemplate } from "@/lib/types/website_page_templates/index_page_template";
const AT = dynamic(() => import("@/features/admin_tools"), {
ssr: false,
@ -13,20 +15,38 @@ export default function ThemePage() {
const pathname = usePathname();
const adminService = useRef(new ThemeAdminService());
const [themeData, setThemeData] = useState<ITheme>();
const [pageTemplate, setPageTemplate] = useState<IndexPageTemplate>();
const fetchTheme = async (pathName: string) => {
setThemeData(await adminService.current.fetchTheme(pathName));
};
const fetchPageTemplate = async () => {
const dynamodbWebsiteTemplateRepo =
new DynamoDBWebsitePageTemplateRepository();
const res = await dynamodbWebsiteTemplateRepo.getIndexPageTemplate();
if (res.status === "success" && res.data) {
setPageTemplate(res.data);
}
};
useEffect(() => {
if (!pathname) return;
const splitPathname = pathname.split("/");
const themePathName = splitPathname[splitPathname.length - 1];
fetchTheme(themePathName);
fetchPageTemplate();
}, [pathname]);
if (themeData) {
return <TP home="/admin" theme={themeData} adminTools={<AT />} />;
if (themeData && pageTemplate) {
return (
<TP
home="/admin"
theme={themeData}
adminTools={<AT />}
pageTemplate={pageTemplate}
/>
);
}
return (

View File

@ -3,9 +3,17 @@ import TP from "@/features/theme_page";
import { DynamoDBThemeRepository } from "@/lib/repositories/theme/dynamodb_theme_repository";
import ITheme from "@/lib/theme/theme";
import ThemeApiService from "@/lib/services/theme/theme_api_service";
import { DynamoDBWebsitePageTemplateRepository } from "@/lib/repositories/website_page_template/dynamodb_website_page_template_repository";
import { IndexPageTemplate } from "@/lib/types/website_page_templates/index_page_template";
export default function ThemePage({ themeData }: { themeData: ITheme }) {
return <TP home="/" theme={themeData} />;
export default function ThemePage({
themeData,
pageTemplate,
}: {
themeData: ITheme;
pageTemplate: IndexPageTemplate;
}) {
return <TP home="/" theme={themeData} pageTemplate={pageTemplate} />;
}
export async function getStaticProps(context: GetServerSidePropsContext) {
@ -14,10 +22,21 @@ export async function getStaticProps(context: GetServerSidePropsContext) {
const adminThemeRepoService = new ThemeApiService(themeRepo);
const res = await adminThemeRepoService.getTheme(path.theme);
if (res.status === "success" && res.data) {
const dynamodbWebsiteTemplateRepo =
new DynamoDBWebsitePageTemplateRepository();
const websiteTemplate =
await dynamodbWebsiteTemplateRepo.getIndexPageTemplate();
if (
res.status === "success" &&
res.data &&
websiteTemplate.status === "success" &&
websiteTemplate.data
) {
return {
props: {
themeData: res.data,
pageTemplate: websiteTemplate.data,
},
revalidate: 60 * 15,
};