Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding images and timestamp #463

Merged
merged 102 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
c8b297b
fix(deps): update dependency @aws-amplify/auth to v4 (#352)
renovate[bot] Mar 23, 2022
0504ac9
Feature: Added Dark theme (#365)
nichnarmada Mar 27, 2022
d789596
fix: clear search keywords when onclick related courses
YHhaoareyou Mar 27, 2022
fba8238
Merge branch 'master' into develop
YHhaoareyou Mar 27, 2022
4cc5b89
Merge branch 'master' into develop
YHhaoareyou Mar 29, 2022
bc8ecd7
Merge branch 'master' into develop
YHhaoareyou Mar 29, 2022
67b4a97
Debug: mobile dark mode debug (#373)
YHhaoareyou Apr 1, 2022
ed25abf
chore(deps): update dependency eslint-plugin-react to v7.29.4 (#361)
renovate[bot] Apr 1, 2022
86a91f5
chore(deps): update dependency ts-loader to v9.2.8 (#359)
renovate[bot] Apr 1, 2022
374a41a
feat: remove unused dependencies (#377)
YHhaoareyou Apr 13, 2022
6632a95
Feature/darktheme colors (#378)
YHhaoareyou Apr 13, 2022
2f8dd9b
Merge branch 'master' into develop
YHhaoareyou Apr 17, 2022
8492b1c
Feature: Timetable dark theme (#379)
YHhaoareyou Apr 18, 2022
66db621
feat: add the hovering effect to the member cards (#381)
xinyue296 Apr 26, 2022
ef10256
Migrate from Webpack to Vite (#382)
YHhaoareyou May 2, 2022
84b2c1d
fix: env without using dotenv explicitly (#385)
YHhaoareyou May 5, 2022
c3abb53
fix: packages version
YHhaoareyou May 5, 2022
5993df1
fix: change env var name
YHhaoareyou May 5, 2022
76976ee
fix: remove systemjs package; add peer dependencies
YHhaoareyou May 5, 2022
e52cdef
fix: feeds domain on staging/prod
YHhaoareyou May 5, 2022
59fdef5
Feature: About Us page link from Home page & split Home from Root-con…
YHhaoareyou May 6, 2022
8252657
Feature/fix card padding (#388)
xinyue296 May 10, 2022
f509547
Merge branch 'master' into develop
YHhaoareyou May 17, 2022
25973a1
fix: install missing dependency: @aws-amplify/core
YHhaoareyou May 17, 2022
8f4caf8
fix: remove course function
YHhaoareyou May 18, 2022
e8a35a6
feat: alert translation
YHhaoareyou May 18, 2022
c0585c1
fix: eslint
YHhaoareyou May 18, 2022
5d47e3c
feat: add workbox runtimeCaching config
YHhaoareyou May 19, 2022
7c6cd35
Fix service worker to enable it to replace old one (#389)
YHhaoareyou May 20, 2022
626ceca
feat: add a profile card component; add hover & click effect; add a c…
xinyue296 May 23, 2022
4bc712d
fix: syllabus minor styling issues
YHhaoareyou May 29, 2022
6245a70
Update README.md
YHhaoareyou May 29, 2022
156663d
Migrate from Webpack to Vite (#386)
YHhaoareyou May 29, 2022
6c911c8
add script-src-elem to Content Security Policy (#391)
YHhaoareyou May 29, 2022
081c41c
Hotfix (#392)
YHhaoareyou May 29, 2022
d1e063a
Hotfix (#393)
YHhaoareyou May 29, 2022
bbc1a69
Merge branch 'master' into develop
YHhaoareyou May 29, 2022
4f556ac
fix blob in csp
YHhaoareyou May 29, 2022
6fa7950
Merge branch 'master' into develop
YHhaoareyou May 30, 2022
8b825bf
fix: remove csp
YHhaoareyou May 30, 2022
893d781
Merge branch 'master' into develop
YHhaoareyou May 30, 2022
0af6214
fix: remove all webpack-related packages & setting
YHhaoareyou May 30, 2022
969da50
Allow all in CSP
YHhaoareyou May 30, 2022
a552f36
Merge branch 'master' into develop
YHhaoareyou May 30, 2022
2505b59
Fix: preload style, csp allow all, refactor index html & env var (#404)
YHhaoareyou May 31, 2022
25cdc27
Update README.md (#397)
eltociear Jun 8, 2022
0bc6cd2
chore(deps): update dependency esbuild to v0.14.43 (#384)
renovate[bot] Jun 8, 2022
c40864e
Merge branch 'master' into develop
AustinZhu Jun 8, 2022
02849a9
chore(deps): update dependencies
AustinZhu Jun 8, 2022
fc74d84
chore(deps): update dependencies
AustinZhu Jun 8, 2022
5470785
chore(deps): update dependencies
AustinZhu Jun 8, 2022
768301a
fix: preload & enable styles from other mf app
YHhaoareyou Jul 6, 2022
6c87d18
fix: packages version (fix React to v17)
YHhaoareyou Jul 6, 2022
b3484e5
Merge branch 'master' into develop
YHhaoareyou Aug 16, 2022
4606cab
Language filter for Feeds (#409)
YHhaoareyou Oct 3, 2022
5f94f13
Merge branch 'master' into develop
YHhaoareyou Oct 27, 2022
10e0f20
feat: added turbo-repo woooo (#420)
nichnarmada Jan 19, 2023
f76867f
Merge branch 'master' into develop
YHhaoareyou Mar 11, 2023
5c1a08b
feat: adding web hooks for forums
JasonNotJson Apr 16, 2023
d0d4ec3
Merge pull request #425 from wasedatime/feat/add-webhook
YHhaoareyou May 3, 2023
5837cc8
feat: updating meet our team page (#426)
JasonNotJson May 5, 2023
2d27b2c
Export Bit components to turborepo packages (#428)
YHhaoareyou May 25, 2023
d04f3c6
Feature: Remove bit from npmrc (#431)
nichnarmada Jun 22, 2023
dffbc9f
fix: fixing tailwind:build from tailwind to tailwindcss
JasonNotJson Jun 22, 2023
714dcbf
feat: reorganizing meet our teams list
JasonNotJson Sep 12, 2023
2e262e7
feat: adding alfonso lien and shiori
JasonNotJson Sep 12, 2023
87a8890
chore: ah comeon
JasonNotJson Sep 12, 2023
f8bf2dc
chore: what in the hell is a JPG and a jpg
JasonNotJson Sep 12, 2023
b70493e
chore: oh Jason focus comeon why are you doing stupid stuff mistaking…
JasonNotJson Sep 12, 2023
a8fc457
feat: adding forum into develop (#446)
JasonNotJson Sep 12, 2023
b345a28
feat: final check on develop now time to deploy
JasonNotJson Sep 12, 2023
ca4437e
feat: merge conflict resolution
JasonNotJson Sep 12, 2023
7d15560
feat: adding type safety to prevent from accessing null length
JasonNotJson Sep 12, 2023
57b72ab
feat: adding array safety
JasonNotJson Sep 12, 2023
0b88bb2
fix: adding another type safety for response array
JasonNotJson Sep 12, 2023
42d3388
feat: adding some common css to see the change
JasonNotJson Sep 12, 2023
8cbb193
feat: altering styling
JasonNotJson Sep 12, 2023
961c070
feat: adding responive ness
JasonNotJson Sep 12, 2023
04d52c8
feat: altered timeline new feature add comment logo no more title and…
JasonNotJson Sep 12, 2023
56f8541
Merge branch 'master' into develop
JasonNotJson Sep 12, 2023
0a557cf
feat: changing our mission
JasonNotJson Sep 12, 2023
a155d54
feat: enlarging the fontsize of forums. Currently it was just too sma…
JasonNotJson Sep 13, 2023
1ccc5b1
fix: fixing App layout and adding onclikc to fix links (#454)
JasonNotJson Sep 13, 2023
9e1eca3
feat: fixing finalization
JasonNotJson Sep 13, 2023
7e3680f
Merge branch 'develop' of https://github.com/wasedatime/wasedatime-we…
JasonNotJson Sep 13, 2023
0a57ff8
feat: adding max width to thread post card
JasonNotJson Sep 13, 2023
8f84951
Merge branch 'master' into develop
JasonNotJson Sep 13, 2023
a83c7d4
feat: added comment count (#456)
JasonNotJson Sep 17, 2023
5575654
fix: fix new feature image size
JasonNotJson Sep 17, 2023
2c972de
feat: resolving merge conflicts
JasonNotJson Sep 17, 2023
36f7e02
feat: adding forum comment notification functionality (#458)
JasonNotJson Sep 18, 2023
d8d4a87
Merge branch 'master' into develop
JasonNotJson Sep 18, 2023
ff74bbb
fix: add Forum route to Root App.tsx
YHhaoareyou Sep 23, 2023
435da46
fix: add Forum routes with params in Root
YHhaoareyou Sep 23, 2023
fb5f8eb
chore: add Forum to sitemap
YHhaoareyou Sep 23, 2023
a2032a4
chore: test hard-coded subpath in Forum
YHhaoareyou Sep 23, 2023
4fea30d
fix: remove hard-coded path and add NotFound in Forum
YHhaoareyou Sep 23, 2023
eb75958
feat: adding images to forums (#460)
JasonNotJson Sep 24, 2023
5f0458e
feat: adding image indicator
JasonNotJson Sep 24, 2023
3e585fa
feat: adding boolean flag for page thread
JasonNotJson Sep 24, 2023
226e8c8
feat: forum-timstamp (#462)
JasonNotJson Sep 28, 2023
70a37d9
chore: fixing git merge conflict
JasonNotJson Sep 30, 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
11 changes: 10 additions & 1 deletion apps/forum/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SearchTags from "./SearchTags";
import FeedBackBox from "./FeedBackBox";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import { API } from "@aws-amplify/api";
import { getUserAttr, getIdToken } from "wasedatime-ui";
import { getUserAttr, getIdToken, LoadingSpinner } from "wasedatime-ui";

const App = () => {
return (
Expand All @@ -25,6 +25,14 @@ const App = () => {

export default App;

const NotFound = () => {
const { theme } = React.useContext(ThemeContext);
const navigate = useNavigate();
useEffect(() => navigate("/"));

return <LoadingSpinner theme={theme} message="Not found! Redirecting..." />;
};

const InnerApp = () => {
const { t, i18n } = useTranslation();

Expand Down Expand Up @@ -108,6 +116,7 @@ const InnerApp = () => {
path="forum/:boardSlug"
/>
<Route element={<Thread />} path="forum/:boardSlug/:threadUuid" />
<Route element={<NotFound />} path="*" />
</Routes>
</div>
<div className="flex flex-col sm:w-1/5 ">
Expand Down
10 changes: 6 additions & 4 deletions apps/forum/src/components/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ConfirmModal } from "@app/components/form/ConfirmModal";
import API from "@aws-amplify/api";
import { getIdToken } from "wasedatime-ui";
import ThreadType from "@app/types/thread";
import { timeFormatter } from "../utils/timeFormatter";

type Props = {
comment: CommentType;
Expand All @@ -18,7 +19,7 @@ type Props = {
const convertUrlsToLinks = (text: string) => {
if (!text) return null;

const urlRegex = /https?:\/\/[^\s]+/g;
const urlRegex: RegExp = /https?:\/\/[^\s]+/g;
const parts = text.split(urlRegex);
const matches = text.match(urlRegex);

Expand Down Expand Up @@ -100,8 +101,6 @@ const Comment = ({ comment, thread, setComments, setThread }: Props) => {
}
);

console.log(res);

const action = "update_decr";
await API.patch(
"wasedatime-dev",
Expand Down Expand Up @@ -129,12 +128,15 @@ const Comment = ({ comment, thread, setComments, setThread }: Props) => {
}
};

const time = timeFormatter(comment);
console.log(comment);

return (
<Block actions={actions}>
<div className="border-2 rounded-xl px-4 py-2 text-light-text2 mt-4 standard-style flex flex-row justify-between items-center">
<div>
<h2 className="text-2xl p-2">{convertUrlsToLinks(comment.body)}</h2>
<h2 className="text-xs my-auto"></h2>
<h2 className="text-xs my-auto">Posted at {time}</h2>
</div>
{comment.mod === true && (
<div className="justify-end">
Expand Down
15 changes: 7 additions & 8 deletions apps/forum/src/components/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const CommentForm: React.FC<CommentFormProps> = ({
);

const newComment: CommentType = response.data;

onNewComment(newComment);
setComment("");

Expand Down Expand Up @@ -105,12 +106,12 @@ const CommentForm: React.FC<CommentFormProps> = ({
}
} catch (error) {
console.error("An error occurred:", error);
} finally {
}
};

return (
<div className="flex justify-between">
{/* <div>Posted at ${time}</div> */}
<input
className="text-2xl text-light-text3 dark:text-dark-text1 w-full focus:text-light-text1 focus:ring border-2 mt-4 mb-2 rounded-lg px-4 py-2 standard-style"
placeholder="Write your comment here (no more than 200 character)"
Expand All @@ -126,13 +127,11 @@ const CommentForm: React.FC<CommentFormProps> = ({
>
<SendIcon />
</span>
{isSignInModalOpen && (
<SignInModal
isModalOpen={isSignInModalOpen}
closeModal={() => setSignInModalOpen(false)}
t={t}
/>
)}
<SignInModal
isModalOpen={isSignInModalOpen}
closeModal={() => setSignInModalOpen(false)}
t={t}
/>
</div>
);
};
Expand Down
61 changes: 54 additions & 7 deletions apps/forum/src/components/CreateThread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import SchoolFilterForm from "./common/SchoolFilter";
import { Menu, Transition } from "@headlessui/react";
import ThreadType from "@app/types/thread";
import TagType from "@app/types/tag";
import ImageIcon from "@mui/icons-material/Image";
import threadPayload from "@app/types/threadPayload";

interface CreateThreadProps {
onNewThread: (newThread: ThreadType) => void;
Expand All @@ -29,6 +31,9 @@ const CreateThread = ({ onNewThread }: CreateThreadProps) => {
const [selectedBoard, setSelectedBoard] = useState("");
const [selectedTag, setSelectedTag] = useState<TagType | null>(null);
const [selectedSchool, setSelectedSchool] = useState("");
const [fileName, setFileName] = useState<string | null>(null);
const [selectedFile, setSelectedFile] = useState<File | null>(null);
const [fileType, setFileType] = useState<string | null>(null);

// Tags and Group buttons might be best moved to their respective components but this is how I will leave it for now.
const { boardSlug } = useParams();
Expand Down Expand Up @@ -81,6 +86,20 @@ const CreateThread = ({ onNewThread }: CreateThreadProps) => {
setSelectedTag(tag);
};

const handleImageChange = (e: ChangeEvent<HTMLInputElement>) => {
const file = e.target.files ? e.target.files[0] : null;
if (file) {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = () => {
const base64data = reader.result as string;
setSelectedFile(base64data); // Store the base64-encoded image
setFileType(file.type); // Store the MIME type of the file
};
setFileName(file.name); // Store the name of the selected file
}
};

const handleSubmit = async () => {
// Require a Board
// If current board isn't chosen, then output this
Expand Down Expand Up @@ -125,18 +144,26 @@ const CreateThread = ({ onNewThread }: CreateThreadProps) => {
}

try {
const payload: threadPayload = {
body: textContent,
title: "default",
tag_id: "default",
group_id: selectedSchool,
univ_id: "1",
board_id: selectedBoard,
};

if (selectedFile) {
payload.image = selectedFile;
payload.contentType = fileType || "";
payload.fileName = fileName || "image";
}
const response = await API.post(
"wasedatime-dev",
`/forum/${selectedBoard}`,
{
body: {
data: {
body: textContent,
title: "default",
tag_id: "default",
group_id: selectedSchool,
univ_id: "1",
},
data: payload,
},
headers: {
"Content-Type": "application/json",
Expand All @@ -158,6 +185,10 @@ const CreateThread = ({ onNewThread }: CreateThreadProps) => {
setTitleContent("");
setTextContent("");
setSelectedBoard("");
setSelectedSchool("");
setSelectedFile(null);
setFileType(null);
setFileName(null);
setSelectedTag(null);
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -308,6 +339,22 @@ const CreateThread = ({ onNewThread }: CreateThreadProps) => {
) : null}
<p>{selectedSchool ? selectedSchool : "School"}</p>
</button>
<div className="uploader">
<label htmlFor="imageUpload" className="cursor-pointer">
{fileName ? (
<span>{fileName}</span>
) : (
<ImageIcon fontSize="large" />
)}
</label>
<input
type="file"
id="imageUpload"
accept="image/png, image/jpeg, image/gif" // allow only images
className="hidden"
onChange={handleImageChange}
/>
</div>
</div>
<button
className="border-light-main border mx-4 px-4 py-1 rounded-lg text-white bg-light-lighter hover:bg-light-darker text-3xl"
Expand Down
8 changes: 8 additions & 0 deletions apps/forum/src/components/Thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const Thread = () => {
setUserToken(userId);
}

let idToken = "";
if (idToken?.length <= 0) {
idToken = await getIdToken();
if (idToken?.length <= 0) return;
}

// Wait for the state to update, then proceed with fetching
// Fetch Threads
await API.get(
Expand All @@ -31,6 +37,7 @@ const Thread = () => {
headers: {
"x-api-key": "0PaO2fHuJR9jlLLdXEDOyUgFXthoEXv8Sp0oNsb8",
"Content-Type": "application/json",
Authorization: idToken,
},
response: true,
}
Expand Down Expand Up @@ -73,6 +80,7 @@ const Thread = () => {
return (
<div className="border-2 mt-12 mx-auto rounded-xl shadow-lg py-6 h-fit px-4 standard-style max-w-2/5 w-5/6">
{/* <CreateThread /> */}

<ThreadBlock isPreview={false} thread={thread} />
<CommentForm
onNewComment={handleNewComment}
Expand Down
29 changes: 24 additions & 5 deletions apps/forum/src/components/ThreadBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import TextsmsIcon from "@mui/icons-material/Textsms";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import boards from "@app/constants/boards.json";
import ThreadType from "@app/types/thread";
import { timeFormatter } from "@app/utils/timeFormatter";
import ImageIcon from "@mui/icons-material/Image";

type Props = {
isPreview: boolean;
Expand Down Expand Up @@ -120,7 +122,6 @@ const ThreadBlock = ({ isPreview, fromRoot, thread, onDelete }: Props) => {
}
);
if (response && response.success) {
console.log(response);
setUserLiked(!userLiked);

if (userLiked) {
Expand Down Expand Up @@ -163,7 +164,7 @@ const ThreadBlock = ({ isPreview, fromRoot, thread, onDelete }: Props) => {
};

const handleShare = () => {
const url = `${window.location.origin}/board/${thread.board_id}/${thread.thread_id}`;
const url = `${window.location.origin}/forum/${thread.board_id}/${thread.thread_id}`;

navigator.clipboard.writeText(url).then(
() => {
Expand All @@ -182,6 +183,7 @@ const ThreadBlock = ({ isPreview, fromRoot, thread, onDelete }: Props) => {

const navigate = useNavigate();

const time = timeFormatter(thread);
const renderContent = () => {
return (
<div
Expand All @@ -202,9 +204,15 @@ const ThreadBlock = ({ isPreview, fromRoot, thread, onDelete }: Props) => {
{/* ^ This line goes to parent board on click while in thread */}
<div className={`px-2`}>
<div className="flex justify-between mt-2">
<h1 className="text-4xl font-bold mb-auto text-light-main dark:text-dark-main text-3xl">
{getTitleBySlug(thread.board_id)}
</h1>
<div className="flex items-center justify-center mb-auto gap-x-4">
<h1 className="text-4xl font-bold text-light-main dark:text-dark-main text-3xl">
{getTitleBySlug(thread.board_id)}
</h1>

<ImageIcon
color={thread.obj_key || thread.url ? "success" : "inherit"}
/>
</div>
<div className="flex justify-center flex-col items-center">
{/* ToDo: create component for tag within Thread Block */}
{thread.group_id && (
Expand All @@ -229,19 +237,30 @@ const ThreadBlock = ({ isPreview, fromRoot, thread, onDelete }: Props) => {
) */}
</div>
</div>
{thread.url ? (
<img
src={thread.url}
alt="Thread Image"
className="block mx-auto p-4"
/>
) : null}
<h2
className="justify-left pt-4 text-light-text1 dark:text-dark-text1"
style={{ whiteSpace: "pre-line" }}
>
{convertUrlsToLinks(isPreview, thread.body)}
</h2>
<h2 className="text-lg mt-5">Posted at {time}</h2>
</div>
{/* <div className="inline-block text-blue-600 rounded-lg pl-2 pt-2">
{" "}
{`# ${thread.tag_id}`}
</div> */}
<hr className="mx-2 pt-2 mt-6" />
{/* horizontal line break */}
<div className="flex flex-row justify-evenly pt-2 items-center">
{/* The down panel that has like button, views in total, etc...*/}

<div className="flex flex-row items-center justify-center">
<button onClick={handleLike} className="clipboard-icon group">
<Favorite
Expand Down
2 changes: 2 additions & 0 deletions apps/forum/src/types/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type ThreadType = {
total_likes?: number;
comment_count?: number;
new_comment?: boolean;
obj_key?: string;
url?: string;
};

export default ThreadType;
12 changes: 12 additions & 0 deletions apps/forum/src/types/threadPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type threadPayload = {
body: string;
title: string;
tag_id: string;
group_id: string;
univ_id: string;
board_id: string;
image?: File;
contentType?: string;
fileName?: string;
};
export default threadPayload;
28 changes: 28 additions & 0 deletions apps/forum/src/utils/timeFormatter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import CommentType from "@app/types/comment";
import ThreadType from "@app/types/thread";

type threadOrComment = CommentType | ThreadType;

export function timeFormatter(newComment: threadOrComment): string {
const utcTimestamp = newComment.created_at;
const date = new Date(utcTimestamp);

// Add 9 hours to UTC time
date.setUTCHours(date.getUTCHours() + 9);

// Extract year, month, date, hours, and minutes
const year = date.getUTCFullYear();
const month = date.getUTCMonth() + 1; // Months are 0-based, so add 1
const day = date.getUTCDate();
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();

// Format the components as a string
const formattedTimestamp = `${year}-${month.toString().padStart(2, "0")}-${day
.toString()
.padStart(2, "0")} ${hours.toString().padStart(2, "0")}:${minutes
.toString()
.padStart(2, "0")}`;

return formattedTimestamp;
}
Loading