-
Notifications
You must be signed in to change notification settings - Fork 0
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
Compare since previous compare PR #4
base: initial
Are you sure you want to change the base?
Changes from 15 commits
3ecc9ef
b947804
5119278
ad77205
69a671d
627dc8f
233b7e8
eb84b11
812d456
3b2d7e2
b0cd8b4
aaeaec0
cf1bde7
660977c
b494a52
4dbcfec
22e7c24
ae941bd
11c9a6e
ca323bb
72db333
631ef8a
4a263fc
41a8b2e
8855891
7620d10
ac1ea6c
b06a3d4
4fa90a9
763e61f
948eaab
8413354
b18ed6a
b0b6b80
9390c2d
b9c09d0
4b48b2c
5842ae0
b949d42
7676ef0
70206b1
dff866e
371de77
2b25ef6
8efdec6
524408f
571c1b0
bc5af78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import * as Types from './types'; | ||
import * as types from './types'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faFaceSmile } from '@fortawesome/free-solid-svg-icons'; | ||
import {comments as initialComments} from './testData' | ||
import {comments as initialComments} from './sampleData' | ||
import { useEffect} from 'react'; | ||
|
||
|
||
export const Comments: React.FC<Types.commentsProps> = ({ comments = initialComments }) => { | ||
export const Comments: React.FC<types.commentsProps> = ({ comments = initialComments, setComments }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may make sense to create a |
||
|
||
useEffect(() => { | ||
// Attempt to load comments from localStorage | ||
const storedCommentsJSON = localStorage.getItem('comments'); | ||
const storedComments = storedCommentsJSON ? JSON.parse(storedCommentsJSON) : null; | ||
|
||
// Check if there are stored comments, otherwise use initial comments | ||
setComments(storedComments || initialComments); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually there will be other places where comments will be rendered, with comments on other types of things even. I think this component should receive one of these as a prop:
I like the second one more. Then the Fetch all project data at page load from project id pointers. But lazy load comment bodies. Make use of "See comments" buttons at times to delay loading. |
||
}, []); // Empty dependency array ensures this runs once on mount | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice comment showing you know how this works. The comment itself is probably unnecessary for production code Edit: This was signaling a linting error, so I disabled this line from the linting process |
||
|
||
|
||
return ( | ||
<div className="comments"> | ||
<span>3 Comments</span> | ||
<span>{comments.length} Comments</span> | ||
<div className="display-comments"> | ||
{comments.map((comment, index) => { | ||
return <> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,59 @@ | ||
|
||
import { CreateCommentProps, comment, commentsProps } from './types'; | ||
import {Comment} from './types'; | ||
import {useState} from 'react'; | ||
|
||
export const CreateComment:React.FC<CreateCommentProps> = ({comments, setComments}) => { | ||
|
||
type CreateCommentProps = { | ||
comments: Comment[], | ||
setComments: (comments: Comment[]) => void; | ||
} | ||
|
||
const handleAddComment = (newComment:comment) => { | ||
let result = [...comments] | ||
result.push(newComment) | ||
setComments(result) | ||
console.log(result) | ||
|
||
|
||
export const CreateComment: React.FC<CreateCommentProps> = ({ comments, setComments }) => { | ||
|
||
const [name, setName] = useState(''); | ||
const [commentText, setCommentText] = useState(''); | ||
|
||
const handleAddComment = () => { | ||
const newComment = { name, commentText }; | ||
|
||
// Fetch existing comments from localStorage | ||
const storedComments = localStorage.getItem('comments'); | ||
const existingComments = storedComments ? JSON.parse(storedComments) : []; | ||
|
||
// Add the new comment to the array | ||
const updatedComments = [...existingComments, newComment]; | ||
|
||
// Save the updated array back to localStorage | ||
localStorage.setItem('comments', JSON.stringify(updatedComments)); | ||
|
||
// Update the local state to reflect the new list of comments | ||
setComments(updatedComments); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swag 👍 🤫 |
||
|
||
|
||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a <textarea> or here to capture the user's comment |
||
<div> | ||
<button onClick={() => handleAddComment({name: "New User", commentText: "This is a new comment."})}> | ||
Add Comment | ||
</button> | ||
<form onSubmit={(e) => { | ||
e.preventDefault(); | ||
handleAddComment(); | ||
setCommentText(''); | ||
}}> | ||
<input | ||
type='text' | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
placeholder='Enter your name' | ||
/> | ||
<input | ||
type='text' | ||
value={commentText} | ||
onChange={(e) => setCommentText(e.target.value)} | ||
placeholder='Type your thoughts here' | ||
/> | ||
<button type='submit'>Add Comment</button> | ||
</form> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import * as Types from './types'; | ||
import * as types from './types'; | ||
|
||
export const Files: React.FC<Types.filesProps> = ({ files }) => { | ||
type FilesProps = { | ||
files: types.File[] | ||
} | ||
|
||
export const Files: React.FC<FilesProps> = ({ files }) => { | ||
return ( | ||
<div className="files"> | ||
<span>+ Files</span> | ||
{files.map((file) => <div id={file.id}> | ||
{files.map((file) => ( | ||
<div id={file.id}> | ||
{file.title} | ||
<br></br> <br></br> | ||
{file.numComments + ' '} | ||
Comments | ||
</div>)} | ||
</div>))} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation looks off here. Should be more like this: {files.map((file) => (
<div id={file.id}>
{file.title}
<br></br> <br></br>
{file.numComments + ' '}
Comments
</div>
))} Also I tend to not use {files.map((file) => (
<div id={file.id}>
<p className='file-title'>{file.title}</p>
<p className='file-num-comments'>
{file.numComments + ' '}
Comments
</p>
</div>
))} .file-title {
margin-bottom: 30px;
} I set them to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sure there's a more appropriate way to make that positioned that way vertically. Also we need to make sure this looks good on mobile |
||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,51 @@ | ||
import * as Types from './types'; | ||
import * as types from './types'; | ||
import React, { useState, FormEvent } from 'react' | ||
|
||
|
||
|
||
|
||
type SectionDataProps = { | ||
sectionData: types.SectionData, | ||
} | ||
|
||
export const SectionTitle: React.FC<SectionDataProps> = ({ sectionData }) => { | ||
const [showForm, setShowForm] = useState(false); //shows the form for when you're entering a new title | ||
const [currentTitle, setCurrentTitle] = useState(sectionData.name); | ||
|
||
let handleToggleForm = () => { | ||
console.log('button clicked'); | ||
setShowForm(!showForm); | ||
}; | ||
|
||
// Handle form submission with FormData for TypeScript | ||
const handleSubmit = (event: FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
const formData = new FormData(event.currentTarget); // Using event.currentTarget to reference the form | ||
const newName = formData.get('newName') as string; | ||
setCurrentTitle(newName); | ||
setShowForm(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting to get the data from the form this way. Any particular reason you preferred this over using |
||
}; | ||
|
||
export const SectionTitle: React.FC<Types.sectionDataProps> = ({ sectionData }) => { | ||
return ( | ||
<div className="section-title"> | ||
<div className='text'> | ||
<h1> {sectionData.name} </h1> | ||
<p>{sectionData.description}</p> | ||
</div> | ||
<div className='buttons'> | ||
<button> {sectionData.numRevisions} revisions </button> | ||
<button> Save revision </button> | ||
<div className="section-title"> | ||
<div className='text'> | ||
<h1>{currentTitle}</h1> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have an idea of user experience of how we can edit the title. I think we should be able to click the current title, or an edit button next to it, and then the title becomes an input box where you can edit its content. Then the submit button changes back to an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For an edit button, we can use the pencil icon from FontAwesome https://fontawesome.com/icons/pencil?f=classic&s=solid |
||
<p>{sectionData.description}</p> | ||
<button onClick={handleToggleForm}> | ||
{showForm ? 'Cancel Editing' : 'Rename Section'} | ||
</button> | ||
</div> | ||
{showForm && ( | ||
<form onSubmit={handleSubmit}> | ||
<label htmlFor="newName">New Name:</label> | ||
<input id="newName" name="newName" type="text" placeholder="Enter new section name" /> | ||
<button type="submit">Update Name</button> | ||
</form> | ||
)} | ||
<div className='revisions'> | ||
<button>{sectionData.numRevisions} revisions</button> | ||
<button>Save revision</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
//To Do for this file: | ||
|
||
//1. make all the data exist in localStorage | ||
|
||
//1.1 that would be comments, number of comments, chord progression, files, title, and description | ||
|
||
//2. type it as asynch even though it's not yet, so it'll be easy to refactor to a backend that isn't localStorage | ||
|
||
export default {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,29 @@ | ||
|
||
import React, { Dispatch } from "react" | ||
|
||
export type sectionData = { | ||
export type SectionData = { | ||
name: string, | ||
description: string, | ||
numRevisions: number | ||
} | ||
|
||
export type sectionDataProps = { | ||
sectionData: sectionData | ||
} | ||
|
||
|
||
|
||
export type chordProgression = string[] | ||
|
||
export type chordProgressionProps = { | ||
chordProgression: chordProgression | ||
} | ||
export type ChordProgression = string[] | ||
|
||
|
||
|
||
export type file = { | ||
export type File = { | ||
title: string, | ||
numComments: number, | ||
id: string, | ||
} | ||
|
||
export type filesProps = { | ||
files: file[] | ||
} | ||
|
||
|
||
export type comment = { | ||
export type Comment = { | ||
name: string, | ||
commentText: string | ||
} | ||
|
||
export type commentsProps = { | ||
comments: comment[] | ||
} | ||
|
||
|
||
|
||
export type CreateCommentProps = { | ||
comments: comment[], | ||
setComments: (comments: comment[]) => void; | ||
} | ||
|
||
|
||
export type appProps = { | ||
sectionData: sectionData, | ||
chordProgression: chordProgression, | ||
files: file[], | ||
comments: comment[] | ||
comments: Comment[] | ||
setComments: (comments: Comment[]) => void; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily a problem, but having two things named the same (this component and
types.ChordProgression
, which is exported as a named export in thetypes.ts
file) can cause issues when you want to use your IDE to import one of those two things. I usually name thisChordProgressionView
or something like that to avoid the name collision