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

Switch to parcel and move component files to new components folder #25

Open
wants to merge 8 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
595 changes: 588 additions & 7 deletions .eslintrc.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ yarn-debug.log*
yarn-error.log*

_ignore

.parcel-cache
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
moduleNameMapper: {
"\\.(css)$": "identity-obj-proxy",
"@/(.*)": "<rootDir>/src/$1"
}
};
25,052 changes: 11,544 additions & 13,508 deletions package-lock.json

Large diffs are not rendered by default.

57 changes: 27 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,43 @@
"name": "section-view",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "parcel src/index.html --dist-dir build",
"build": "parcel build src/index.html --dist-dir build",
"test": "jest",
"test:ci": "jest --watchAll=false",
"lint": "eslint src/**/*.ts src/**/*.tsx",
"fix": "npm run lint -- --fix",
"check-types": "tsc --noEmit",
"ci": "npm run lint && npm run check-types && npm run test:ci && npm run build"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.5.2",
"@fortawesome/free-brands-svg-icons": "^6.5.2",
"@fortawesome/free-regular-svg-icons": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^4.9.5"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.94",
"@types/react": "^18.2.74",
"@types/react-dom": "^18.2.24",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test:ci": "react-scripts test --watchAll=false",
"eject": "react-scripts eject",
"lint": "eslint src/**/*.ts*",
"fix": "npm run lint -- --fix",
"check-types": "tsc --noEmit",
"ci": "npm run lint && npm run check-types && npm run test:ci && npm run build"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.32.0",
"eslint": "^8.44.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"identity-obj-proxy": "^3.0.0",
"jest-environment-jsdom": "^29.7.0",
"parcel": "^2.12.0",
"ts-jest": "^29.1.5"
}
}
Binary file removed public/favicon.ico
Binary file not shown.
43 changes: 0 additions & 43 deletions public/index.html

This file was deleted.

Binary file removed public/logo192.png
Binary file not shown.
Binary file removed public/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions public/robots.txt

This file was deleted.

4 changes: 2 additions & 2 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {render, screen, waitFor} from '@testing-library/react';
import App from './App';
import {IClient} from './client/IClient';
import {ProjectData, CommentData, SectionData, EntityType, FileData} from './types';
import {ProjectData, CommentData, SectionData, EntityType, FileData} from './types/music_sniper_types';
import {LocalStorageStore, StoreData} from './store/LocalStorageStore';
import {MockLocalStorageDependency} from './store/MockLocalStorageDependency';
import {LocalStorageClient} from './client/LocalStorageClient';

// import * as testData from './sampleData'

window.alert = () => {};
globalThis.alert = () => {};

const makeTestStore = (): StoreData => {
const initialProjects: ProjectData[] = [
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import './App.css';
import './css_reset.css'
import './index.css'
import './section_view.css';
import * as types from './types';
import * as types from './types/music_sniper_types';
import {GlobalStoreProvider} from './hooks/useGlobalStore';
import SectionPage from './SectionPage';
import SectionPage from './components/SectionPage';
import {IClient} from './client/IClient';
import {ClientProvider} from './hooks/useClient';
import {useMount} from './hooks/useMount';
Expand Down
16 changes: 0 additions & 16 deletions src/ChordProgression.tsx

This file was deleted.

5 changes: 2 additions & 3 deletions src/actions/useActions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useClient} from '../hooks/useClient';
import {useGlobalStore} from '../hooks/useGlobalStore';
import {CommentData, EntityPointer, SectionData} from '../types';
import {CommentData, EntityPointer, SectionData} from '../types/music_sniper_types';

type UseActionsHookValue = {
addCommentToEntity(text: string, username: string, entityPointer: EntityPointer): Promise<CommentData>;
Expand All @@ -11,7 +11,6 @@ export const useActions = (): UseActionsHookValue => {
const globalStore = useGlobalStore();
const client = useClient();

// TODO: this should be retrieved from globalState
// const projectId = globalStore.getCurrentProjectId()
const projectId = 'project-1';

Expand Down Expand Up @@ -41,4 +40,4 @@ export const useActions = (): UseActionsHookValue => {
addCommentToEntity,
updateSection,
};
}
};
2 changes: 1 addition & 1 deletion src/client/IClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CommentData, FullProjectData, SectionData} from '../types';
import {CommentData, FullProjectData, SectionData} from '../types/music_sniper_types';

export interface IClient {
fetchFullDataForProject: (projectId: string) => Promise<FullProjectData | Error>;
Expand Down
19 changes: 10 additions & 9 deletions src/client/LocalStorageClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {LocalStorageStore} from '../store/LocalStorageStore';
import {CommentData, FullProjectData, SectionData} from '../types';
import {CommentData, FullProjectData, SectionData} from '../types/music_sniper_types';

import {IClient} from './IClient';

export class LocalStorageClient implements IClient {
Expand All @@ -20,15 +21,15 @@ export class LocalStorageClient implements IClient {
this.persistentStore.setAllComments(newState);

return newComment;
}
};

// fetchFullDataForProject uses the local storage store to get all data for a given project
// it fetches the project data, sections, files, and comments for the given project
fetchFullDataForProject = async (projectId: string): Promise<FullProjectData | Error> => {
const projects = (await this.persistentStore.getAllProjects()).filter(p => p.id === projectId);
const sections = (await this.persistentStore.getAllSections()).filter(s => s.projectId === projectId);
const files = (await this.persistentStore.getAllFiles()).filter(f => f.projectId === projectId);
const comments = (await this.persistentStore.getAllComments()).filter(c => c.projectId === projectId);
const projects = (await this.persistentStore.getAllProjects()).filter((p) => p.id === projectId);
const sections = (await this.persistentStore.getAllSections()).filter((s) => s.projectId === projectId);
const files = (await this.persistentStore.getAllFiles()).filter((f) => f.projectId === projectId);
const comments = (await this.persistentStore.getAllComments()).filter((c) => c.projectId === projectId);

if (!projects[0]) {
return new Error(`Error: No project found for projectId ${projectId}`);
Expand All @@ -40,11 +41,11 @@ export class LocalStorageClient implements IClient {
files,
sections,
};
}
};

updateSection = async (sectionId: string, section: SectionData): Promise<SectionData> => {
const sections = await this.persistentStore.getAllSections();
const newState = sections.map(s => {
const newState = sections.map((s) => {
if (s.id === sectionId) {
return section;
}
Expand All @@ -55,5 +56,5 @@ export class LocalStorageClient implements IClient {
this.persistentStore.setAllSections(newState);

return section;
}
};
}
18 changes: 18 additions & 0 deletions src/components/ChordProgression.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as types from '@/types/music_sniper_types';

type ChordProgressionProps = {
chordProgression: types.ChordProgression;
}

export const ChordProgression = ({chordProgression}: ChordProgressionProps) => {
return (
<div className='chords'>
<ol>
{chordProgression.map((chord, index) => (
// eslint-disable-next-line react/no-array-index-key
<li key={index}>{chord}</li>
))}
</ol>
</div>
);
};
16 changes: 8 additions & 8 deletions src/Comments.tsx → src/components/Comments.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import {faFaceSmile} from '@fortawesome/free-solid-svg-icons';

import {EntityPointer} from './types';
import {useGlobalStore} from './hooks/useGlobalStore';
import {plural} from './utils';
import {EntityPointer} from '@/types/music_sniper_types';
import {useGlobalStore} from '@/hooks/useGlobalStore';
import {plural} from '@/utils';

type CommentsProps = {
entityPointer: EntityPointer;
}

export const Comments: React.FC<CommentsProps> = ({entityPointer}) => {
export const Comments = ({entityPointer}: CommentsProps) => {
const globalStore = useGlobalStore();
const comments = globalStore.getCommentsForEntity(entityPointer);

return (
<div className="comments">
<div className='comments'>
<span>{comments.length} {plural('Comment', comments.length)}</span>
<div className="display-comments">
{comments.map(comment => (
<div className='display-comments'>
{comments.map((comment) => (
<p
key={comment.id}
id={comment.id}
>
<FontAwesomeIcon icon={faFaceSmile} />
<FontAwesomeIcon icon={faFaceSmile}/>
{comment.username}: {comment.message}
</p>
))}
Expand Down
12 changes: 6 additions & 6 deletions src/CreateComment.tsx → src/components/CreateComment.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

import {useActions} from './actions/useActions';
import {EntityPointer} from './types';
import {useState} from 'react';

import {useActions} from '@/actions/useActions';
import {EntityPointer} from '@/types/music_sniper_types';

type CreateCommentProps = {
entityPointer: EntityPointer;
}

export const CreateComment: React.FC<CreateCommentProps> = ({entityPointer}) => {
export const CreateComment = ({entityPointer}: CreateCommentProps) => {
const actions = useActions();

const [name, setName] = useState('');
Expand All @@ -18,7 +18,7 @@ export const CreateComment: React.FC<CreateCommentProps> = ({entityPointer}) =>

await actions.addCommentToEntity(commentText, name, entityPointer);
setCommentText('');
}
};

return (
<div>
Expand All @@ -37,7 +37,7 @@ export const CreateComment: React.FC<CreateCommentProps> = ({entityPointer}) =>
/>
<button
type='submit'
disabled={!Boolean(name && commentText)}
disabled={!(name && commentText)}
>
Add Comment
</button>
Expand Down
Loading
Loading