Skip to content

Commit

Permalink
Merge pull request #3 from yungshenglu/develop
Browse files Browse the repository at this point in the history
add: List title and bug fixing
  • Loading branch information
yungshenglu authored Mar 27, 2021
2 parents 470e0d7 + 35fd7f6 commit 7a1996f
Show file tree
Hide file tree
Showing 32 changed files with 218 additions and 283 deletions.
8 changes: 8 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Release Notes

---

## [v0.0.3](https://github.com/yungshenglu/Dcard-Reader/releases/tag/v0.0.3)

- Features
- Add the title for the list of the latest popular posts
- Fix bugs of the infinite scrolling
- Code refactoring

## [v0.0.2](https://github.com/yungshenglu/Dcard-Reader/releases/tag/v0.0.2)

- Features
Expand Down
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const axios = require('axios');
const cors = require('cors');


const app = express();

app.use(cors({
Expand Down Expand Up @@ -40,7 +41,7 @@ app.get('/api/post&id=:id', (req, res) => {
return '';
}
}).catch((err) => {
res.send(id);
res.send(err);
});
});

Expand Down
Binary file modified assets/img/Demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import Router from './router';


function App() {
return (
<div className="App">
Expand Down
3 changes: 2 additions & 1 deletion src/components/AntAvatar/AntAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import PropTypes from 'prop-types';
import { AAvatar } from '@P/antd';


export function AntAvatar({ ...props }: any) {
return <AAvatar {...props} />;
}

AntAvatar.prototype = {
props: PropTypes.object
}
};
3 changes: 2 additions & 1 deletion src/components/AntBacktop/AntBacktop.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import PropTypes from 'prop-types';
import { StyledAntBacktop } from './style';


export function AntBacktop({ ...props }: any) {
return <StyledAntBacktop {...props} />;
}

AntBacktop.prototype = {
props: PropTypes.object
}
};
3 changes: 2 additions & 1 deletion src/components/AntBadge/AntBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import PropTypes from 'prop-types';
import { ABadge } from '@P/antd';


export function AntBadge({ ...props }: any) {
return <ABadge {...props} />;
}

AntBadge.prototype = {
props: PropTypes.object
}
};
1 change: 1 addition & 0 deletions src/components/AntCol/AntCol.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import { ACol } from '@P/antd';


export function AntCol({ children, ...props }: any) {
return <ACol {...props}>{children}</ACol>;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/AntEmpty/style.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from 'styled-components';
import { AEmpty } from '@P/antd';


export const StyledEmpty = styled(AEmpty)`
color: #000;
`;
1 change: 1 addition & 0 deletions src/components/AntNotification/AntNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import { ANotification } from '@P/antd';


export function AntNotification({ ...props }: any) {
return ANotification.error({
message: props.messages,
Expand Down
1 change: 1 addition & 0 deletions src/components/AntRow/AntRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import { ARow } from '@P/antd';


export function AntRow({ children, ...props }: any) {
return <ARow {...props}>{children}</ARow>;
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/AntTag/AntTag.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';

import { ATag } from '@P/antd';


export function AntTag({ children, style, color }: any) {
return (
<ATag style={style} color={color}>
Expand Down
1 change: 1 addition & 0 deletions src/components/CusItemExcerpt/CusItemExcerpt.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import { StyledItemExcerpt } from './style';


export function CusItemExcerpt({ content }: any) {
return (
<StyledItemExcerpt>
Expand Down
1 change: 1 addition & 0 deletions src/components/CusItemExcerpt/style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from 'styled-components';


export const StyledItemExcerpt = styled.div`
background: transparent;
color: #000;
Expand Down
46 changes: 5 additions & 41 deletions src/components/CusItemTitle/CusItemTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,17 @@
import { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import AntNotification from '@C/AntNotification';
import CusPostModal from '@C/CusPostModal';
import useFetchPost from '@H/useFetchPost';
import { StyledItemTitle } from './style';


export function CusItemTitle({ content, id }: any) {
const [modalVisible, setModalVisible] = useState(false);
const [{ data, isLoading, isError }, refetch]: any = useFetchPost(id);

useEffect(() => {
if (isError) {
AntNotification({
message: '系統錯誤',
description: '目前連線異常,請稍後再試。'
});
}
}, [isError]);

// Event handler
const handleOpenModal = async () => {
setModalVisible(true);
await refetch();
}

const handleCloseModal = () => {
setModalVisible(false);
}

export function CusItemTitle({ content, itemId }: any) {
// Render
return (
<>
<StyledItemTitle onClick={handleOpenModal} margin>
{ content }
</StyledItemTitle>
<CusPostModal
modalTitle={content}
modalData={data}
isLoading={isLoading}
isError={isError}
modalVisible={modalVisible}
onCloseModal={handleCloseModal}
/>
</>
<StyledItemTitle margin>
{ content }
</StyledItemTitle>
);
};

CusItemTitle.prototype = {
content: PropTypes.string,
id: PropTypes.number
itemId: PropTypes.number
};
78 changes: 41 additions & 37 deletions src/components/CusList/CusList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,31 @@ import PropTypes from 'prop-types';
import AntEmpty from '@C/AntEmpty';
import AntSkeleton from '@C/AntSkeleton';
import CusListItem from '@C/CusListItem';
import { StyledList, StyledSpinContainer } from './style';
import { StyledList } from './style';


export function CusList({ listData = [], isLoading = true, lastItemRef }: any) {
// console.log('listData: ', listData);
export function CusList({ listData = [], isLoading, lastItemRef }: any) {
const listLength = listData?.length;

// Render
return (
<StyledList>
{
isLoading
? null
: listData
? listData.map((item: any, index: number) => {
if (index === listLength - 1) {
return (
<>
<div
ref={lastItemRef}
data-id={item.id}
>
<CusListItem
key={item.id}
id={item.id}
title={item.title}
excerpt={item.excerpt}
gender={item.gender}
forumName={item.forumName}
topics={item.topics}
commentCount={item.commentCount}
divider={index !== listLength - 1}
/>
</div>
{ isLoading ? <AntSkeleton active/> : null }
</>
)
} else {
return (
listData?.length === 0
? isLoading
? <AntSkeleton active />
: <AntEmpty />
: listData.map((item: any, index: number) => {
if (index === listLength - 1) {
return (
<>
<div
key={`${item.id}${index}`}
ref={lastItemRef}
data-id={item.id}
>
<CusListItem
key={item.id}
id={item.id}
itemId={item.id}
title={item.title}
excerpt={item.excerpt}
gender={item.gender}
Expand All @@ -52,10 +35,31 @@ export function CusList({ listData = [], isLoading = true, lastItemRef }: any) {
commentCount={item.commentCount}
divider={index !== listLength - 1}
/>
)
}
})
: <AntEmpty />
{
isLoading
? <AntSkeleton active/>
: null
}
</div>
</>
)
} else {
return (
<div key={`${item.id}${index}`}>
<CusListItem
itemId={item.id}
title={item.title}
excerpt={item.excerpt}
gender={item.gender}
forumName={item.forumName}
topics={item.topics}
commentCount={item.commentCount}
divider={index !== listLength - 1}
/>
</div>
)
}
})
}
</StyledList>
);
Expand Down
5 changes: 1 addition & 4 deletions src/components/CusList/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ export const StyledList = styled.div`
height: 100%;
background: #FFF;
padding: 20px;
overflow-y: scroll;
`;

export const StyledSpinContainer = styled.div`
text-align: center;
`
Loading

0 comments on commit 7a1996f

Please sign in to comment.