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

Compare since previous compare PR #4

Open
wants to merge 48 commits into
base: initial
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3ecc9ef
Refactor CSS reset to its own file. Standardize naming conventions
aelishRollo Apr 12, 2024
b947804
Change .parent to .root
aelishRollo Apr 12, 2024
5119278
Make sectionData, currentChordProgression, files, and comments, data …
aelishRollo Apr 12, 2024
ad77205
Refactor files to be its own component
aelishRollo Apr 13, 2024
69a671d
Refactor ChordProgression into a component
aelishRollo Apr 13, 2024
627dc8f
Refactor Chordprogression for to include the <div> with class chords
aelishRollo Apr 13, 2024
233b7e8
Refactor Files so <div> with class 'files' is all together
aelishRollo Apr 13, 2024
eb84b11
Refactor comments section into its own component
aelishRollo Apr 13, 2024
812d456
Refactor submit section into its own component
aelishRollo Apr 13, 2024
3b2d7e2
Refactor Section-Title into its own component
aelishRollo Apr 13, 2024
b0cd8b4
Give all component return statements pretty parentheses
aelishRollo Apr 20, 2024
aaeaec0
Refactor sectionData to be passed in as a prop
aelishRollo Apr 22, 2024
cf1bde7
Refactor chord progression component to use props
aelishRollo Apr 23, 2024
660977c
Refactor files component to use props
aelishRollo Apr 23, 2024
b494a52
Refactor Comments to use props
aelishRollo Apr 23, 2024
4dbcfec
Add an id for the array of files
aelishRollo Apr 24, 2024
22e7c24
Move type definitions to Types.ts
aelishRollo Apr 24, 2024
ae941bd
Add types to testData.ts
aelishRollo Apr 25, 2024
11c9a6e
Remove unnecessary import
aelishRollo Apr 25, 2024
ca323bb
Add export keywords to testData.ts
aelishRollo Apr 25, 2024
72db333
Move all data to testData.tsx
aelishRollo Apr 25, 2024
631ef8a
Refactor App.tsx to accept testData as a prop
aelishRollo Apr 26, 2024
4a263fc
Prepare to refactor components to their own files
aelishRollo Apr 26, 2024
41a8b2e
Refactor components to their own files
aelishRollo Apr 26, 2024
8855891
Add comments as state variable, hoist it
aelishRollo Apr 27, 2024
7620d10
Remove extra map from .submit
aelishRollo Apr 27, 2024
ac1ea6c
Rename Submit component to CreateComment
aelishRollo Apr 27, 2024
b06a3d4
Fix comment update bug
aelishRollo Apr 30, 2024
4fa90a9
Remove unnecessary imports
aelishRollo Apr 30, 2024
763e61f
Fix overflow issue when adding a new comment
aelishRollo Apr 30, 2024
948eaab
Make all types start with uppercase character
aelishRollo May 1, 2024
8413354
Move AppProps to App.jsx
aelishRollo May 1, 2024
b18ed6a
Move CreateCommentProps to CreateComment.tsx
aelishRollo May 1, 2024
b0b6b80
Move FilesProps definition to Files.tsx
aelishRollo May 1, 2024
9390c2d
Move ChordProgressionProps to ChordProgression.tsx
aelishRollo May 1, 2024
b9c09d0
Move SectionDataProps to SectionData.tsx
aelishRollo May 1, 2024
4b48b2c
Change 'Types' to 'types'
aelishRollo May 1, 2024
5842ae0
Change '.buttons' to '.revisions'
aelishRollo May 2, 2024
b949d42
User can now rename section title
aelishRollo May 3, 2024
7676ef0
Add parenthese to returned JSX
aelishRollo May 3, 2024
70206b1
Make amount of comments show on page
aelishRollo May 3, 2024
dff866e
Prep to move to localStorage
aelishRollo May 7, 2024
371de77
Make comments persistant using localStorage
aelishRollo May 8, 2024
2b25ef6
Rename testData.tsx to sampleData.tsx
aelishRollo May 8, 2024
8efdec6
Move comments data to localStorage
aelishRollo May 9, 2024
524408f
Create ci workflows for build and type checking (#7)
mickmister May 12, 2024
571c1b0
Update README.md
aelishRollo May 24, 2024
bc5af78
Refactor to use local storage (#8)
mickmister Jun 1, 2024
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
146 changes: 110 additions & 36 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,123 @@
import './App.css';
import './SectionView.css';
import './css_reset.css'
import './section_view.css';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faFaceSmile } from '@fortawesome/free-solid-svg-icons';

function App() {
mickmister marked this conversation as resolved.
Show resolved Hide resolved
return (
<div className="parent">
<div className="section-title">
<div className='text'>
<h1> Intro </h1>
<p>This intro section consists of a tuba quartet in the style of DJ Templeton & The Windsurfers</p>
</div>
<div className='buttons'>
<button> 42 revisions </button>
<button> save revision </button>
</div>
</div>
<div className="chords">
<ol>
<li>C</li>
<li>Dm</li>
<li>F</li>
<li>G</li>
</ol>
</div>
<div className="files">
<span>+ Files</span>
<div>Bass.mp3 <br></br> <br></br> 2 Comments</div>
<div>Drums.mp3 <br></br> <br></br> 2 Comments</div>
<div>Yodeling.mp3 <br></br> <br></br> 2 Comments </div>
<div>Tuba.mp3 <br></br> <br></br> 2 Comments </div>
</div>
<div className="comments">
<span>3 Comments</span>
<div className="display-comments">
<p><FontAwesomeIcon icon={faFaceSmile} /> Jerry: My name is Schmoopie and I love this song. It reminds me of my grandpa</p>
<p><FontAwesomeIcon icon={faFaceSmile} /> Larry: jokes on you! Im deaf.</p>
<p><FontAwesomeIcon icon={faFaceSmile} /> Terry: Notice the tinnitus ringing in your ears, let the hiss from your damaged hearing remind you of peaceful ocean waves...</p>
</div>



const sectionData = {
name: 'Intro',
description: 'This intro section consists of a tuba quartet in the style of DJ Templeton & The Windsurfers',
numRevisions: 42,
};

const currentChordProgression = ['C', 'Dm', 'F', 'G']

const files = [
{
title: 'Bass.mp3',
numComments: 2,
},
mickmister marked this conversation as resolved.
Show resolved Hide resolved
{
title: 'Drums.mp3',
numComments: 2,
},
{
title: 'Yodeling.mp3',
numComments: 2,
},
{
title: 'Tuba.mp3',
numComments: 2,
},
]


const comments = [
{
name: 'Jerry',
commentText: 'My name is Schmoopie and I love this song. It reminds me of my grandpa'
},
{
name: 'Lerry',
commentText: 'jokes on you! Im deaf.'
},
{
name: 'Jerry',
commentText: 'Notice the tinnitus ringing in your ears, let the hiss from your damaged hearing remind you of peaceful ocean waves...'
},
]


// Components

function Files() {
Copy link
Member Author

Choose a reason for hiding this comment

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

We have all of the components defined inside of this App component, as well as the creation of the test data happening inside of the component. This has a side effect of making it so React has no context of when things "change" here, or when they have "stayed the same" between renders.

The reference to the child component definitions are changing every time, and the data being passed in as props (at least they likely will be later). For minimal refactoring to improve this, I recommend the following making the following changes:

Create types.ts

export type FileInfo = {
  id: string;
  // ...
}

// Other types...

Create testdata.ts

import {
  FileInfo,
  // Other types...
} from './types';

const files: FileInfo[] = [
  {
    id: '1',
    title: 'my_file_name'.mp3,
    // ...
  },
  // ...
];

const comments: Comment[] = [

];

export const testData = {
  // this is shorthand for `files: files`
  files,
  comments,
}

Then in App.tsx

import {
  FileInfo,
  Comment,
} from './types';

import {testData} from './testdata';

function App() {
  return (
    <div className="root">
      <SectionTitle sectionData={testData.sectionData} />
      <ChordProgression chordProgression={testData.chordProgression} />
      <Files files={testData.files} />
      <Comments comments={testData.comments} />
      <Submit />
    </div>
  );
}

// Files component

type FilesProps = {
  files: FileInfo
}

function Files(props: FileProps) {
  // then use `props.files` to render things
} 

We define components like Files outside of the definition of App. Ideally these are defined in their own files, but keeping them in the same file as App is less work for now. Separating the definitions to be on the module-level of the file is important though.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, so do you want me to move the components to their own files?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah each of the components seem separate enough to warrant living in their own individual files

Copy link
Member Author

Choose a reason for hiding this comment

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

Also vscode and typescript make it really easy to move components into other files. You can highlight the text of the component, then right-click and select "Refactor..." (I prefer to use the command palette and type "refactor" instead of right-clicking), then select "Move to a new file". It generates a new file, which you can then rename and relocate as necessary. vscode will automatically:

  • Move that component's function to a new file, and export it as a named export
  • Import that component in the original file
  • Move/copy and necessary imports (like React) into the new file, and remove them from this file if they are no longer used anywhere in this file

You don't have to do any of these things. It just does it for you. It's called "refactor" here since the change is made cleanly, and the functionality of the program doesn't change

Copy link
Member

Choose a reason for hiding this comment

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

Yeah man, I love the refactor command! It's so useful

return <div className="files">
<span>+ Files</span>
{files.map((file) =>
<div>
{file.title}
mickmister marked this conversation as resolved.
Show resolved Hide resolved
<br></br> <br></br>
{file.numComments + ' '}
Comments
</div>)}
</div>
}


function ChordProgression() {
return <div className="chords">
<ol>
{currentChordProgression.map((chord, index) => <li>{chord}</li>)}
</ol>
</div>
}


function Comments() {
return <div className="comments">
<span>3 Comments</span>
<div className="display-comments">
{comments.map((comment, index) => {
return <>
<p><FontAwesomeIcon icon={faFaceSmile} /> {comments[index].name}: {comments[index].commentText}</p>
</>
})}
</div>
<div className="submit">
</div>
}

function Submit() {
return <div className="submit">
<textarea placeholder="make a comment"></textarea>
<button>Submit</button>
</div>
Copy link
Member Author

Choose a reason for hiding this comment

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

It probably makes sense to have the submit button trigger an update to the array of comments shown. That would make the code more ready for porting over.

We would add a prop to this Submit component for the parent component to process the form submission.

Also, I'm thinking this component can be called CreateComment to be more specific about what it's doing. We can then have the passed in callback prop to be called onSubmit. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I think that renaming the component to CreateComment is a good idea for sure, since the name is now more clear as to its purpose.

I believe that in order for this component to update the array of comments shown, there are a few options we could go for, namely:

  • just adding a comment to the array (low complexity, but only a temporary soltion)
  • adding the array to local storage and actually updating the array there (a bit more involved but more of a long term solution)

What are your thoughts on this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm thinking localStorage will be useful to help with mocking the actual backend now. Probably good idea to have a client.ts file that acts like we're fetching and saving to the backend. That will handle all localStorage things behind the scenes. Here, client refers to "http client" in a way. It's our gateway to the backend's endpoints, but we can fake the client's implementation with localStorage for now.

export const fetchAllDataForSectionPage = async (sectionId: string): Promise<SectionPageAllData> => {
    return getSectionDataFromLocalStorage(sectionId);
};

export const addNewCommentToSection = async (sectionId: string, commentText: string): Promise<Comment> => {
    const sectionData = getSectionDataFromLocalStorage(sectionId);
    const id = Math.random().toString().slice(2); // generate random string
    const newComment: Comment = {
        id,
        message: commentText,
    };

    sectionData.comments.push(comment);
    saveSectionDataToLocalStorage(sectionId, sectionData);
    return newComment;
};

After this we can have a browse project page that will help show other aspects of the UI. It would be a view where you can select a given section in a project. Then we could also have a projects browser that allows you to see a list of projects. What do you think?

}

function SectionTitle() {
return <div className="section-title">
<div className='text'>
<h1> {sectionData.name} </h1>
mickmister marked this conversation as resolved.
Show resolved Hide resolved
<p>{sectionData.description}</p>
mickmister marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div className='buttons'>
<button> {sectionData.numRevisions} revisions </button>
<button> Save revision </button>
</div>
</div>
}

return (
<div className="root">
<SectionTitle />
<ChordProgression />
<Files />
<Comments />
<Submit />
</div>
);
}

Expand Down
48 changes: 48 additions & 0 deletions src/css_reset.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
62 changes: 1 addition & 61 deletions src/SectionView.css → src/section_view.css
Original file line number Diff line number Diff line change
@@ -1,63 +1,3 @@
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}









/* END OF CSS RESET */




* {
Expand All @@ -67,7 +7,7 @@ table {
html {font-size: 62.5%;}


.parent {
.root {
display: flex;
background-color: rgb(95, 193, 208);
justify-content: center;
Expand Down