Skip to content
Closed
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
bee43e4
first-commit
fordelord Dec 8, 2022
d066a4f
little-fix
fordelord Dec 8, 2022
678c67c
fix-type-temporarily
fordelord Dec 8, 2022
774f106
test-with-post
fordelord Dec 12, 2022
b424d2f
Merge branch 'master' into editor-mode-code-
fordelord Dec 12, 2022
deffb4c
remove-test
fordelord Dec 12, 2022
1a17ac8
improvment-by-cookie-&-result-version
fordelord Dec 20, 2022
7b5f56f
Merge branch 'master' into editor-mode-code-
fordelord Dec 20, 2022
7d3148c
remake-index-file-for-netlify
fordelord Dec 20, 2022
9955712
Merge branch 'editor-mode-code-' of https://github.com/1alexvash/Alex…
fordelord Dec 20, 2022
20e3520
Update yarn.lock
fordelord Dec 20, 2022
e29a1e1
remake-functional-to-localStorage
fordelord Dec 22, 2022
6137239
add-breakpoint
fordelord Dec 22, 2022
ab448ba
remove-useful-npm
fordelord Dec 22, 2022
18672bf
change-name-slice
fordelord Dec 22, 2022
a19b21d
Merge branch 'editor-mode-code-' of https://github.com/1alexvash/Alex…
fordelord Dec 22, 2022
6475744
remove-useful-npm
fordelord Dec 22, 2022
a5e63d1
Update yarn.lock
fordelord Dec 22, 2022
08d4a62
Update yarn.lock
fordelord Dec 22, 2022
b1a39f9
change-name
fordelord Dec 22, 2022
e72cf4c
Merge branch 'editor-mode-code-' of https://github.com/1alexvash/Alex…
fordelord Dec 22, 2022
2033da2
change-double-click-event
fordelord Dec 23, 2022
81cbccb
remove-useless-fragment
fordelord Dec 23, 2022
1618fca
fix-by-code-review-&-improvements
fordelord Jan 9, 2023
5848e5e
remove-admin-type
fordelord Jan 9, 2023
b276f84
fix-hr-element-&-remove-class-edit-background
fordelord Jan 10, 2023
43ac166
remove-localstorage-check-to-boolean
fordelord Jan 10, 2023
2793040
test-to-fix-error
fordelord Jan 10, 2023
e48bef9
test-to-fix-error
fordelord Jan 10, 2023
628f9ba
test-to-fix-error
fordelord Jan 10, 2023
cbc0c8d
fix-problem
fordelord Jan 10, 2023
331d260
correct-check-localStorage
fordelord Jan 10, 2023
0d00cee
change-equation-&-change-helper-usUpcomingPost
fordelord Jan 10, 2023
d1566c7
changes-by-review
fordelord Jan 12, 2023
f742ac1
change-className
fordelord Jan 12, 2023
76166c5
change-name-of-icon
fordelord Jan 13, 2023
28615b0
add-upcoming-posts-styles-&-add-animation-&-fixes
fordelord Jan 16, 2023
19e98f8
Merge branch 'master' into editor-mode-code-
fordelord Jan 16, 2023
5bb938f
change-test-condition
fordelord Jan 16, 2023
2ee9b31
remove-magic-number
fordelord Jan 17, 2023
1b01b4e
implement-feature-of-count-tags-in-admin
fordelord Jan 30, 2023
f65560a
change-import-admin-state
fordelord Jan 30, 2023
4649e63
change-number-to-square-brackets
fordelord Jan 31, 2023
fda802a
Merge branch 'master' into editor-mode-code-
fordelord Feb 27, 2023
4580d44
fix-an-arror-after-merge
fordelord Feb 27, 2023
55f2712
refactor-upcomingPost-component-to-MUI
fordelord Mar 1, 2023
60ce23d
remake-postImg-after-style
fordelord Mar 1, 2023
f0b10b5
merge-two-style-into-one
fordelord Mar 1, 2023
e020a28
Resolve merge conflicts
1alexvash Mar 4, 2023
69fbaf9
changes-by-code-review
fordelord Mar 5, 2023
b6f0958
refactor-intro-component-to-mui
fordelord Mar 6, 2023
122b503
remove-useless-className
fordelord Mar 6, 2023
4977a57
change-color-name-to-correct
fordelord Mar 6, 2023
942726b
changes-by-code-review
fordelord Mar 6, 2023
52b6637
change-name-of-variable-to-correct
fordelord Mar 6, 2023
1da996c
Merge branch 'master' into editor-mode-code-
fordelord Mar 6, 2023
e370af1
changes-by-prettier
fordelord Mar 6, 2023
3903690
Merge pull request #82 from 1alexvash/refactor-introSection-component
fordelord Mar 16, 2023
732869a
remove admin edit icon
fordelord May 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions components/AdminProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { setAdmin } from "redux/slices/admin";
import { useAppDispatch } from "redux/typesHooks";

import useIsomorphicLayoutEffect from "./useIsomorphicLayoutEffect";

interface Props {
children: JSX.Element;
}

const getAdmin = (): boolean | undefined => {
return localStorage.admin === "true";
};

const getInitialAdmin = (): boolean => getAdmin() || false;

const AdminProvider = ({ children }: Props) => {
const dispatch = useAppDispatch();

useIsomorphicLayoutEffect(() => {
const admin = getInitialAdmin();

dispatch(setAdmin(admin));
}, [dispatch]);

return children;
};

export default AdminProvider;
100 changes: 77 additions & 23 deletions components/Intro.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,84 @@
import config from "config";
import { useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import { setAdmin } from "redux/slices/admin";
import { useAppSelector } from "redux/typesHooks";

const Intro = () => (
<section className="intro-section">
<div className="container">
<div className="intro-content">
<div className="intro-avatar">
<div className="image">
<img
src="/images/author-avatar.jpg"
alt="author-avatar"
width={90}
height={90}
/>
const Intro = () => {
const dispatch = useDispatch();
const admin = useAppSelector((state) => state.admin);

const [isFirstRender, setIsFirstRender] = useState(true);

const handleClick = () => {
if (admin === true) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (admin === true) {
if (admin) {

It's a same thing

dispatch(setAdmin(false));
} else {
dispatch(setAdmin(true));
}
};

useEffect(() => {
const imageWrapper = document.querySelector("div.image-avatar");
const editIcon = document.querySelector("img.editor-icon");

if (admin) {
imageWrapper?.setAttribute("admin", "");
editIcon?.setAttribute("admin", "");
setIsFirstRender(false);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a break line down below, for the consistency

if (!admin && isFirstRender === false) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!admin && isFirstRender === false) {
if (!admin && !isFirstRender) {

Use the same syntax for both of them

imageWrapper?.setAttribute("closing", "");
editIcon?.setAttribute("closing", "");
imageWrapper?.addEventListener(
"animationend",
() => {
editIcon?.removeAttribute("closing");
imageWrapper?.removeAttribute("closing");
},
{ once: true }
);
imageWrapper?.removeAttribute("admin");
editIcon?.removeAttribute("admin");
}
}, [admin, isFirstRender]);

return (
<section className="intro-section">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do MUI in here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#82 - refactor of MUI component. I think it will be easier for you to check this refactor if it will be like another PR.

<div className="container">
<div className="intro-content">
<div className="intro-avatar">
<div className="image-avatar">
<img
onDoubleClick={handleClick}
src="/images/author-avatar.jpg"
alt="author-avatar"
width="90"
height="90"
/>
</div>
<div className="image-editor">
<img
className="editor-icon"
src="/images/editor-icon.svg"
alt="edit"
width="19"
height="19"
/>
</div>
<div className="name">{config.author_name}</div>
<div className="job">{config.author_position}</div>
</div>
<div className="intro-text">
<h1>Hello, I am {config.author_name}</h1>
<p style={{ whiteSpace: "break-spaces" }}>
{config.site_description}
</p>
</div>
<div className="name">{config.author_name}</div>
<div className="job">{config.author_position}</div>
</div>
<div className="intro-text">
<h1>Hello, I am {config.author_name}</h1>
<p style={{ whiteSpace: "break-spaces" }}>
{config.site_description}
</p>
</div>
</div>
</div>
</section>
);
</section>
);
};

export default Intro;
12 changes: 3 additions & 9 deletions components/Post/LatestPosts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
isPostADraft,
isPostInTheFuture,
} from "helpers/checkOfDraftOrFuturePost";
import isUpcomingPost from "helpers/isUpcomingPost";
import { PostDocumentWithoutContent } from "interfaces";
import Image from "next/image";
import Link from "next/link";
Expand All @@ -28,11 +25,8 @@ const LatestPosts = ({ latestPosts }: Props) => {
height="102"
sizes="100vw"
style={{
filter:
isPostADraft(post) || isPostInTheFuture(post)
? "grayscale(50%)"
: "none",

filter: isUpcomingPost(post) ? "grayscale(50%)" : "none",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this utility function


objectFit: "cover",
}}
/>
Expand Down
6 changes: 2 additions & 4 deletions components/Post/PostContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
isPostADraft,
isPostInTheFuture,
} from "helpers/checkOfDraftOrFuturePost";
import isUpcomingPost from "helpers/isUpcomingPost";
import toHumanReadableDate from "helpers/toHumanReadableDate";
import { PostDocument } from "interfaces";
import Head from "next/head";
Expand Down Expand Up @@ -53,10 +54,7 @@ const PostContent = ({ post }: Props) => {
width={790}
height={394}
style={{
filter:
isPostADraft(post) || isPostInTheFuture(post)
? "grayscale(50%)"
: "none",
filter: isUpcomingPost(post) ? "grayscale(50%)" : "none",
borderRadius: "3px",
}}
/>
Expand Down
10 changes: 3 additions & 7 deletions components/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
isPostADraft,
isPostInTheFuture,
} from "helpers/checkOfDraftOrFuturePost";
import isUpcomingPost from "helpers/isUpcomingPost";
import { PostDocumentWithoutContent } from "interfaces";
import Image from "next/image";
import Link from "next/link";
Expand Down Expand Up @@ -57,9 +58,7 @@ const PostCard = ({ post }: Props) => {

<div
className={`posts-list-block ${
isPostADraft(post) || isPostInTheFuture(post)
? "posts-list-block-draft-or-future"
: ""
isUpcomingPost(post) ? "upcoming-posts-list-block" : ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With MUI it is probably going to look differently

}`}
>
<div className="content">
Expand All @@ -75,10 +74,7 @@ const PostCard = ({ post }: Props) => {
height="378"
sizes="100vw"
style={{
filter:
isPostADraft(post) || isPostInTheFuture(post)
? "grayscale(50%)"
: "none",
filter: isUpcomingPost(post) ? "grayscale(50%)" : "none",

objectFit: "cover",
}}
Expand Down
7 changes: 5 additions & 2 deletions components/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { useAppDispatch, useAppSelector } from "redux/typesHooks";

interface Props {
uniqueTags: string[];
countOfPostsInTags: number[];
}

const Tags = ({ uniqueTags }: Props) => {
const Tags = ({ uniqueTags, countOfPostsInTags }: Props) => {
const selectedTags = useAppSelector((state) => state.selectedTags);
const admin = useAppSelector((state) => state.admin);

const dispatch = useAppDispatch();

Expand All @@ -27,7 +29,7 @@ const Tags = ({ uniqueTags }: Props) => {
>
ALL
</li>
{uniqueTags.map((uniqueTag) => (
{uniqueTags.map((uniqueTag, index) => (
<li
key={uniqueTag}
className={selectedTags.includes(uniqueTag) ? "active" : ""}
Expand All @@ -44,6 +46,7 @@ const Tags = ({ uniqueTags }: Props) => {
}}
>
{uniqueTag}
{admin && ` [${countOfPostsInTags[index]}]`}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{admin && ` [${countOfPostsInTags[index]}]`}
{admin && `[${countOfPostsInTags[index]}]`}

Extra space?

Copy link
Contributor Author

@fordelord fordelord Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It look more readable with this space, removed this space

</li>
))}
</ul>
Expand Down
37 changes: 37 additions & 0 deletions components/UpcomingPosts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Box, Divider, Typography } from "@mui/material";
import { PostDocumentWithoutContent } from "interfaces";

import PostCard from "./PostCard";

interface Props {
posts: PostDocumentWithoutContent[];
}

const UpcomingPosts = ({ posts }: Props) => (
<Box sx={{ mb: 17.5 }}>
<Box>
<Typography
sx={(theme) => ({
color: theme.palette.mode === "light" ? "#3a3a3a" : "#fff",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
color: theme.palette.mode === "light" ? "#3a3a3a" : "#fff",
color: theme.palette.mode === "light" ? "#3a3a3a" : "white",

white is easier to read, so even non programmers can understand your code

lineHeight: 1.28,
fontWeight: 700,
fontSize: "43px",
mb: 9,
["@media (max-width: 480px)"]: {
fontSize: "28px",
},
})}
>
Upcoming Posts
</Typography>
</Box>
<ul className="posts-list">
{posts.map((post, index) => (
<PostCard key={index} post={post} />
))}
</ul>
<Divider sx={{ position: "absolute", width: "100%", left: 0 }} />
</Box>
);

export default UpcomingPosts;
7 changes: 7 additions & 0 deletions helpers/isUpcomingPost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PostDocumentWithoutContent } from "interfaces";

import { isPostADraft, isPostInTheFuture } from "./checkOfDraftOrFuturePost";

export default function isUpcomingPost(post: PostDocumentWithoutContent) {
return isPostADraft(post) || isPostInTheFuture(post);
}
18 changes: 16 additions & 2 deletions helpers/markdownDocumentsReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import matter from "gray-matter";
import { PostDocument, PostDocumentWithoutContent } from "interfaces";
import { join } from "path";

import { isPostADraft, isPostInTheFuture } from "./checkOfDraftOrFuturePost";
import isUpcomingPost from "./isUpcomingPost";

const documentsDirectory = join(process.cwd(), "content/posts");

Expand Down Expand Up @@ -31,7 +31,7 @@ export function getAllPostDocuments(): PostDocumentWithoutContent[] {
return true;
}

if (isPostADraft(post) || isPostInTheFuture(post)) {
if (isUpcomingPost(post)) {
return false;
}

Expand All @@ -45,3 +45,17 @@ export function getAllPostDocuments(): PostDocumentWithoutContent[] {

return JSONSerialize(docs);
}

export function getUpcomingPosts(): PostDocumentWithoutContent[] {
const slugs = fs.readdirSync(documentsDirectory);
const docs = slugs
.map((slug) => getPostDocumentBySlug(slug))
.filter((post: PostDocument) => isUpcomingPost(post))
.sort((post1, post2) => (post1.date > post2.date ? -1 : 1))
.map((post) => {
const { content, ...postWithoutContent } = post;
return postWithoutContent;
});

return JSONSerialize(docs);
}
Comment on lines +48 to +61
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tina CMS is fetching posts somewhat differently, so it might cause some merge conflicts

I might merge Tina first, and only then you're going to update this utility method

9 changes: 6 additions & 3 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import type { AppProps } from "next/app";
import { Provider } from "react-redux";
import store from "redux/store";

import AdminProvider from "@/components/AdminProvider";
import GoogleAnalytics from "@/components/GoogleAnalytics";
import ThemeProvider from "@/components/MUI/ThemeProvider";

const MyApp = ({ Component, pageProps }: AppProps) => (
<Provider store={store}>
<GoogleAnalytics />

<ThemeProvider>
<Component {...pageProps} />
</ThemeProvider>
<AdminProvider>
<ThemeProvider>
<Component {...pageProps} />
</ThemeProvider>
</AdminProvider>
</Provider>
);

Expand Down
8 changes: 8 additions & 0 deletions pages/api/getUpcomingPosts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getUpcomingPosts } from "helpers/markdownDocumentsReader";
import type { NextApiRequest, NextApiResponse } from "next";

export default function handler(req: NextApiRequest, res: NextApiResponse) {
const posts = getUpcomingPosts();

res.status(200).json(posts);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tina GraphQL query might look a bit differently, so just heads up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, waiting for merge of Tina and after will be fixing that

Loading