-
Notifications
You must be signed in to change notification settings - Fork 105
Task4: Circle of contributors #851
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
Open
MrH233
wants to merge
9
commits into
hypertrons:master
Choose a base branch
from
MrH233:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f14faf9
#808 task
MrH233 55f9740
Merge remote-tracking branch 'origin/master'
johnathon0715 211a012
Merge remote-tracking branch 'origin/master'
johnathon0715 abd7e6d
Merge remote-tracking branch 'origin/master'
johnathon0715 ea19adb
更新组件css样式,保留切换前的原样;更新效果图片
johnathon0715 de5b7a5
Merge remote-tracking branch 'origin/master'
johnathon0715 f67f894
使用prettier更新format
johnathon0715 97a3520
① Modified button and interface styles to be consistent with GitHub s…
johnathon0715 bd7399d
Merge remote-tracking branch 'origin/master'
MrH233 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| ## Task 808 | ||
|
|
||
| 增加新组件 "contributor_button": | ||
|
|
||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th width="50%">初始化按钮: 仓库首页显示贡献者活跃网络</th> | ||
| <th width="50%">点击按钮: 仓库首页贡献者模块切换为原头像矩阵</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td> | ||
| <img | ||
| src="https://raw.githubusercontent.com/MrH233/hypertrons-crx/master/picture/点击前.png" | ||
| /> | ||
| </td> | ||
| <td> | ||
| <img | ||
| src="https://raw.githubusercontent.com/MrH233/hypertrons-crx/master/picture/点击后.png" | ||
| /> | ||
| </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| **组员:黄小鹏 51265903102**<br> | ||
| **组员:朱奕帆 51265903116**<br> | ||
| **组员:王超亚 51265903103**<br> |
|
MrH233 marked this conversation as resolved.
Outdated
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
|
MrH233 marked this conversation as resolved.
Outdated
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions
26
src/pages/ContentScripts/features/contributor_button/DataNotFound.tsx
|
MrH233 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import React from 'react'; | ||
|
|
||
| const DataNotFound = () => { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| color: 'var(--color-fg-muted)', | ||
| }} | ||
| > | ||
| <h3>Data Not Found</h3> | ||
| <div style={{ width: '300px', margin: '2em' }}> | ||
| <p>Possible reasons are:</p> | ||
| <ul style={{ marginLeft: '1em' }}> | ||
| <li>This repository is too new, so its data has not been generated</li> | ||
| <li>This repository is not active enough, so its data are not generated</li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DataNotFound; | ||
|
Comment on lines
+1
to
+26
Collaborator
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. Let's move the |
||
77 changes: 77 additions & 0 deletions
77
src/pages/ContentScripts/features/contributor_button/index.tsx
|
MrH233 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * 该模块负责在GitHub仓库页面中,增强贡献者列表的功能。 | ||
| * 它使用React来渲染贡献者列表,并通过API获取额外的网络数据。 | ||
| */ | ||
|
|
||
| import React, { useState, useEffect } from 'react'; | ||
| import { render } from 'react-dom'; | ||
| import $ from 'jquery'; | ||
| import View from './view'; | ||
| import { getRepoName } from '../../../../helpers/get-repo-info'; | ||
| import { getDeveloperNetwork, getRepoNetwork } from '../../../../api/repo'; | ||
| import features from '../../../../feature-manager'; | ||
| import * as pageDetect from 'github-url-detection'; | ||
| import elementReady from 'element-ready'; | ||
|
|
||
| // 全局变量用于存储仓库名称和网络数据,以便在不同函数间共享 | ||
| // 定义全局变量,用于存储仓库名称和网络数据。 | ||
| let repoName: string; | ||
| let developerNetworks: any; | ||
| let repoNetworks: any; | ||
| let target: any; | ||
|
|
||
| // 获取当前模块的特征ID,用于特性管理。 | ||
| const featureId = features.getFeatureID(import.meta.url); | ||
|
|
||
| /** | ||
| * 异步获取仓库开发者和仓库的网络数据。 | ||
| */ | ||
| const getData = async () => { | ||
| developerNetworks = await getDeveloperNetwork(repoName); | ||
| repoNetworks = await getRepoNetwork(repoName); | ||
| }; | ||
|
|
||
| /** | ||
| * 替换贡献者列表为React组件。 | ||
| * @param target 要替换的目标元素。 | ||
| */ | ||
| const replaceContributorList = (target: HTMLElement) => { | ||
| const originalHTML = target.innerHTML; | ||
|
|
||
| render( | ||
| <React.Fragment> | ||
| <View developerNetwork={developerNetworks} target={originalHTML} /> | ||
| </React.Fragment>, | ||
| document.querySelector('.list-style-none.d-flex.flex-wrap.mb-n2') as HTMLElement | ||
| ); | ||
| }; | ||
|
|
||
|
MrH233 marked this conversation as resolved.
|
||
| /** | ||
| * 初始化功能,包括获取仓库名称和数据,以及替换贡献者列表。 | ||
| */ | ||
| const init = async (): Promise<void> => { | ||
| repoName = getRepoName(); | ||
| const targetElement = document.querySelector('.list-style-none.d-flex.flex-wrap.mb-n2') as HTMLElement; | ||
| await getData(); | ||
| replaceContributorList(targetElement); | ||
| }; | ||
|
|
||
| /** | ||
| * 在页面刷新或导航时恢复功能,重新加载数据和渲染列表。 | ||
| */ | ||
| const restore = async () => { | ||
| if (repoName !== getRepoName()) { | ||
| repoName = getRepoName(); | ||
| await getData(); | ||
| } | ||
| $('div.ReactModalPortal').remove(); | ||
| replaceContributorList(target); | ||
| }; | ||
|
|
||
| // 将功能添加到特性管理器中,配置初始化和恢复函数。 | ||
| features.add(featureId, { | ||
| // asLongAs: [pageDetect.isUserProfile], | ||
| awaitDomReady: false, | ||
| init, | ||
| restore, | ||
| }); | ||
80 changes: 80 additions & 0 deletions
80
src/pages/ContentScripts/features/contributor_button/view.tsx
|
MrH233 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import React, { useState, useEffect } from 'react'; | ||
| import ReactModal from 'react-modal'; | ||
| import Graph from '../../../../components/Graph'; | ||
| import optionsStorage, { HypercrxOptions, defaults } from '../../../../options-storage'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import '../../../../helpers/i18n'; | ||
|
|
||
| // 定义开发者和仓库的时间周期 | ||
| const DEVELOPER_PERIOD = 90; | ||
| const REPO_PERIOD = 90; | ||
|
|
||
| // 定义Props接口,包括开发者网络和目标HTML | ||
| interface Props { | ||
| developerNetwork: any; | ||
| target: any; | ||
| } | ||
|
|
||
| // 定义图表样式 | ||
| const graphStyle = { | ||
| width: '296px', | ||
| height: '400px', | ||
| }; | ||
|
|
||
| const targetStyle = { | ||
| width: '296px', | ||
| height: '100px', | ||
| display: 'flex', | ||
| 'justify-content': 'flex-start', | ||
| 'align-items': 'flex-start', | ||
| 'align-content': 'flex-start', | ||
| 'flex-wrap': 'wrap', | ||
| }; | ||
|
|
||
| const buttonStyle = { | ||
| margin: '-5px 0px 10px 0px', | ||
| padding: '8px', | ||
| 'border-radius': '15px', | ||
| }; | ||
|
|
||
| // 定义View组件 | ||
| const View = ({ developerNetwork, target }: Props): JSX.Element => { | ||
| // 定义状态变量,包括选项、是否显示图表和是否显示仓库网络 | ||
| const [options, setOptions] = useState<HypercrxOptions>(defaults); | ||
| const [showGraph, setShowGraph] = useState(true); | ||
| const [showRepoNetwork, setShowRepoNetwork] = useState(false); | ||
|
|
||
| // 使用翻译函数 | ||
| const { t, i18n } = useTranslation(); | ||
|
|
||
| // 使用useEffect钩子来处理副作用,包括获取选项和改变语言 | ||
| useEffect(() => { | ||
| (async function () { | ||
| setOptions(await optionsStorage.getAll()); | ||
| i18n.changeLanguage(options.locale); | ||
| })(); | ||
| }, [options.locale]); | ||
|
|
||
| // 返回JSX元素,包括一个按钮和一个条件渲染的图表或目标HTML | ||
| return ( | ||
| <div> | ||
| <button onClick={() => setShowGraph(!showGraph)} style={buttonStyle}> | ||
| 切换视图 | ||
| </button> | ||
| {showGraph ? ( | ||
| <div className="hypertrons-crx-border hypertrons-crx-container"> | ||
| <div className="d-flex flex-wrap flex-items-center" style={{ margin: '0 0 0 0', padding: '0' }}> | ||
| <div style={{ margin: '0 0 0 0', padding: '0', display: 'block' }}> | ||
| <Graph data={developerNetwork} style={graphStyle} /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ) : ( | ||
| <div dangerouslySetInnerHTML={{ __html: target }} style={targetStyle} /> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| // 导出View组件 | ||
| export default View; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.