Skip to content

Commit e37d7d4

Browse files
authored
Merge pull request #158 from xsnippet/convert-components-to-ts
Convert some components to ts && add image module
2 parents 78dfdec + c2124af commit e37d7d4

File tree

15 files changed

+8352
-12390
lines changed

15 files changed

+8352
-12390
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"named": "never"
3131
}],
3232
"@typescript-eslint/no-explicit-any": "off",
33-
"@typescript-eslint/explicit-module-boundary-types": "off"
33+
"@typescript-eslint/explicit-module-boundary-types": "off",
34+
"@typescript-eslint/no-var-requires": "off"
3435
}
3536
}

package-lock.json

Lines changed: 8299 additions & 12362 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
"moduleNameMapper": {
2828
"^.+\\.(css|styl|svg|jpg)$": "identity-obj-proxy"
2929
},
30-
"testURL": "http://localhost"
30+
"testURL": "http://localhost",
31+
"transform": {
32+
"^.+\\.(js|jsx|ts|tsx)$": "ts-jest"
33+
}
3134
},
3235
"dependencies": {
3336
"brace": "^0.11.0",
@@ -51,13 +54,15 @@
5154
"@babel/preset-react": "^7.0.0",
5255
"@babel/preset-typescript": "^7.12.7",
5356
"@babel/runtime": "^7.12.5",
57+
"@types/enzyme": "^3.10.8",
58+
"@types/jest": "^26.0.20",
5459
"@types/parse-link-header": "^1.0.0",
5560
"@types/react": "^17.0.0",
5661
"@types/react-dom": "^17.0.0",
62+
"@types/react-router-dom": "^5.1.7",
5763
"@typescript-eslint/eslint-plugin": "^4.14.0",
5864
"@typescript-eslint/parser": "^4.14.0",
5965
"babel-core": "^7.0.0-bridge.0",
60-
"babel-jest": "^23.4.2",
6166
"babel-loader": "^8.0.0",
6267
"clean-webpack-plugin": "^0.1.17",
6368
"css-loader": "^0.28.7",
@@ -70,11 +75,12 @@
7075
"html-webpack-plugin": "^3.2.0",
7176
"identity-obj-proxy": "^3.0.0",
7277
"image-webpack-loader": "^5.0.0",
73-
"jest": "^22.0.4",
78+
"jest": "^26.6.3",
7479
"mini-css-extract-plugin": "^0.4.0",
7580
"style-loader": "^0.19.0",
7681
"stylus": "^0.54.5",
7782
"stylus-loader": "^3.0.1",
83+
"ts-jest": "^26.4.4",
7884
"typescript": "^4.1.3",
7985
"webpack": "^4.45.0",
8086
"webpack-cli": "^3.1.1",

src/assets.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
declare module '*.jpg' {
2+
const src: string;
3+
export default src;
4+
}
5+
6+
declare module '*.svg' {
7+
import * as React from 'react';
8+
9+
export const ReactComponent: React.FC<React.SVGProps<
10+
SVGElement
11+
> & { title?: string }>;
12+
13+
const src: string;
14+
export default src;
15+
}

src/components/About.jsx renamed to src/components/About.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Fragment } from 'react'
1+
import React, { Fragment, FC } from 'react'
22

33
import Title from './common/Title'
44

@@ -9,7 +9,7 @@ import KaterynaImage from '../assets/photos/kateryna.jpg'
99

1010
import '../styles/AboutUs.styl'
1111

12-
const About = () => (
12+
const About: FC = () => (
1313
<Fragment>
1414
<div className="about">
1515
<Title title="About" />

src/components/Header.jsx renamed to src/components/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React from 'react'
1+
import React, { FC } from 'react'
22
import { NavLink } from 'react-router-dom'
33

44
import Logo from '../assets/icons/xsnippet.svg'
55

66
import '../styles/Header.styl'
77

8-
const Header = () => (
8+
const Header: FC = () => (
99
<header className="header">
1010
<div className="header-logo">
1111
<NavLink exact to="/">

src/components/Sidebar.jsx renamed to src/components/Sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react'
1+
import React, { FC } from 'react'
22
import { NavLink } from 'react-router-dom'
33

44
import '../styles/Sidebar.styl'
55

6-
const Sidebar = () => (
6+
const Sidebar: FC = () => (
77
<nav className="sidebar">
88
<ul className="sidebar-list">
99
<li className="sidebar-item">

src/components/common/Spinner.jsx renamed to src/components/common/Spinner.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react'
1+
import React, { FC } from 'react'
22
import SpinnerImg from '../../assets/icons/ripple.svg'
33

44
import '../../styles/common/Spinner.styl'
55

6-
const Spinner = () => (
6+
const Spinner: FC = () => (
77
<div className="spinner">
88
<img src={SpinnerImg} alt="Loading..." />
99
</div>

src/components/common/Title.jsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/components/common/Title.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React, { FC } from 'react'
2+
3+
import '../../styles/common/Title.styl'
4+
5+
const Title: FC<{title:string, additionalClass?:string}> = ({ title, additionalClass = '' }) => (
6+
<div className={`title ${additionalClass}`}>{title}</div>
7+
)
8+
9+
export default Title
File renamed without changes.

tests/components/common/Title.test.jsx renamed to tests/components/common/Title.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ import { shallow } from 'enzyme'
33

44
import Title from '../../../src/components/common/Title'
55

6+
const title = 'Snippet page';
7+
68
describe('Title', () => {
79
it('should return correct title', () => {
8-
const wrapper = shallow(<Title title="Snippet page" />)
9-
expect(wrapper.text()).toEqual('Snippet page')
10+
const wrapper = shallow(<Title title={title} />)
11+
expect(wrapper.text()).toEqual(title)
1012
})
1113

1214
it('should have additional class if one was provided', () => {
13-
const wrapper = shallow(<Title additionalClass="custom-title" />)
15+
const wrapper = shallow(<Title title={title} additionalClass="custom-title" />)
1416
expect(wrapper.hasClass('custom-title')).toEqual(true)
1517
})
1618

1719
it('should not have additional class if one wasn\'t provided', () => {
18-
const wrapper = shallow(<Title />)
20+
const wrapper = shallow(<Title title={title} />)
1921
expect(wrapper.hasClass('custom-title')).toEqual(false)
2022
})
2123
})

tests/helpers/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('misc', () => {
66
const snippet = {
77
content: 'const memoizedSyntaxes = useMemo()',
88
created_at: '2019-09-29T19:23:31',
9-
id: 364066,
9+
id: '364066',
1010
syntax: 'javascript',
1111
tags: ['trg', 'rtyger'],
1212
title: 'some misterious title',
@@ -26,7 +26,7 @@ describe('misc', () => {
2626
})
2727

2828
it('should return propper title', () => {
29-
const untitled = { ...snippet, title: undefined }
29+
const untitled = { ...snippet, title: '' }
3030
const expected = `#${untitled.id}, Untitled`
3131

3232
expect(getSnippetTitle(untitled)).toEqual(expected)

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"target": "es5",
66
"jsx": "react",
77
"allowJs": true,
8-
"allowSyntheticDefaultImports": true
8+
"allowSyntheticDefaultImports": true,
9+
"esModuleInterop": true
910
},
1011
"include": [
1112
"src/"

0 commit comments

Comments
 (0)