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

User no longer chooses date when creating/updating article. #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 3 additions & 19 deletions components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { TAGS } from '@/constants';
interface FormData {
title: string;
content: string;
// created_date: Date;
// updated_date: Date;
// created_date: Date;
updated_date: Date;
sections: string[];
quick_link: boolean;
image_url: string;
Expand All @@ -34,15 +34,9 @@ const Form = ({ formId, articleForm, forNewArticle = true }: Props) => {
const [message, setMessage] = useState('');

const [form, setForm] = useState<FormData>({
// created_date: articleForm.created_date,
// updated_date: articleForm.updated_date,
// content: articleForm.content,
// image_url: articleForm.image_url,
title: articleForm.title,
content: articleForm.content,
// TODO
// created_date: new Date(),
// updated_date: new Date(),
updated_date: new Date(),
sections: articleForm.sections,
quick_link: false,
image_url: articleForm.image_url,
Expand Down Expand Up @@ -155,16 +149,6 @@ const Form = ({ formId, articleForm, forNewArticle = true }: Props) => {
required
/>

<label htmlFor="date">Date</label>
<input
type="date"
name="created_date"
value={Date.now()}
onChange={handleChange}
/>

{/* tags sections*/}

<label htmlFor="sections">Sections</label>
{TAGS.map((tag, index) => (
<div key={index}>
Expand Down
2 changes: 1 addition & 1 deletion pages/[id]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const EditArticle = () => {
title: article.title,
content: article.content,
created_date: article.created_date,
updated_date: article.updated_date,
updated_date: new Date(),
image_url: article.image_url,
quick_link: article.quick_link,
// TODO
Expand Down
53 changes: 53 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,51 @@ export type Props = {
articles: Articles[];
};

const parseDateString = (str: string) => {
let year: string = str.slice(0, 4);
let month: string = str.slice(5, 7);
let day: string = str.slice(8, 10);
let hour = str.slice(11, 13);
let min: string = str.slice(14, 16);

let hour_num = Number(hour);
let day_num = Number(day);
hour_num -= 7;

if (hour_num < 0) {
hour_num = 24 + hour_num;
day_num -= 1;
}

let ampm: string = 'XM';
if (hour_num > 12) {
ampm = 'PM';
hour_num -= 12;
} else {
ampm = 'AM';
}

let time: string = `${hour_num}:${min} ${ampm}`;

const monthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

let monthName = monthNames[Number(month) - 1];
return `${monthName} ${day_num}, ${year} at ${time}`;
};

const Index = ({ articles }: Props) => {
return (
<>
Expand All @@ -28,6 +73,14 @@ const Index = ({ articles }: Props) => {
<p className="sections">
Sections: {article.sections.join(', ')}
</p>
<p className="created_date">
Created date:{' '}
{parseDateString(article.created_date.toLocaleString())}
</p>
<p className="updated_date">
Updated date:{' '}
{parseDateString(article.updated_date.toLocaleString())}
</p>

<div className="btn-container">
<Link
Expand Down