Skip to content

Commit

Permalink
Merge pull request #44 from type-challenges/dev
Browse files Browse the repository at this point in the history
release-20240607
  • Loading branch information
ZLY201 authored Jun 7, 2024
2 parents 9b24892 + 5a6f2ce commit 6e3d0a5
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 30 deletions.
10 changes: 5 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Typescript-Tutorial-Exercises Contributing Guide
# Type-Challenges-Site Contributing Guide

Hi! I'm really excited that you are interested in contributing to js-sdsl. Before submitting your contribution, please make sure to take a moment and read through the following guidelines:

- [Code of Conduct](https://github.com/typescript-tutorial-exercises/core/blob/main/CODE_OF_CONDUCT.md)
- [Code of Conduct](https://github.com/type-challenges/site/blob/main/CODE_OF_CONDUCT.md)
- [Issue Reporting Guidelines](#issue-reporting-guidelines)
- [Pull Request Guidelines](#pull-request-guidelines)
- [Development Setup](#development-setup)
Expand Down Expand Up @@ -44,7 +44,7 @@ $ yarn setup

### Committing Changes

Please follow the commit specification. See [`.commitlintrc.json`](https://github.com/typescript-tutorial-exercises/core/blob/main/.commitlintrc.json) get help.
Please follow the commit specification. See [`.commitlintrc.json`](https://github.com/type-challenges/site/blob/main/.commitlintrc.json) get help.

### Commonly used NPM scripts

Expand All @@ -68,6 +68,6 @@ All our source files are written in typescript, please make sure your submission

## Credits

Thank you to all the people who have already contributed to `typescript-tutorial-exercises`!
Thank you to all the people who have already contributed to `type-challenges`!

[![contributors](https://contrib.rocks/image?repo=typescript-tutorial-exercises/core)](https://github.com/typescript-tutorial-exercises/core/graphs/contributors)
[![contributors](https://contrib.rocks/image?repo=type-challenges/site)](https://github.com/type-challenges/site/graphs/contributors)
1 change: 0 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# These are supported funding model platforms

open_collective: typescript-tutorial-exercises
custom: ["https://www.paypal.com/paypalme/zly201"]
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jobs:
folder: dist
branch: gh-pages
token: ${{ secrets.DEPLOY_TOKEN }}
repository-name: typescript-tutorial-exercises/preview
repository-name: type-challenges/site
- name: Deploy to github pages
if: ${{ github.ref == 'refs/heads/main' }}
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist
branch: gh-pages
token: ${{ secrets.DEPLOY_TOKEN }}
repository-name: typescript-tutorial-exercises/typescript-tutorial-exercises.github.io
repository-name: type-challenges/type-challenges.github.io
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Typescript Tutorial Exercise

[![status](https://img.shields.io/github/actions/workflow/status/typescript-tutorial-exercises/core/deploy.yml)](https://github.com/typescript-tutorial-exercises/core/actions/workflows/deploy.yml)
[![stars](https://img.shields.io/github/stars/typescript-tutorial-exercises/core.svg)](https://github.com/typescript-tutorial-exercises/core)
[![status](https://img.shields.io/github/actions/workflow/status/type-challenges/site/deploy.yml)](https://github.com/type-challenges/site/actions/workflows/deploy.yml)
[![stars](https://img.shields.io/github/stars/type-challenges/site.svg)](https://github.com/type-challenges/site)
[![licenses](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![language](https://img.shields.io/github/languages/top/typescript-tutorial-exercises/core.svg)](https://github.com/typescript-tutorial-exercises/core)
[![language](https://img.shields.io/github/languages/top/type-challenges/site.svg)](https://github.com/type-challenges/site)

## Getting Started

Please go to [typescript-tutorial-exercises.github.io](https://typescript-tutorial-exercises.github.io/) to start your TypeScript travel!
Please go to [type-challenges.github.io](https://type-challenges.github.io/) to start your TypeScript travel!

All exercises are from [type-challenges](https://github.com/type-challenges/type-challenges).

Expand All @@ -19,7 +19,7 @@ Feel free to dive in! Open an issue or submit PRs. It may be helpful to read the

Thanks goes to these wonderful people:

[![contributors](https://contrib.rocks/image?repo=typescript-tutorial-exercises/core)](https://github.com/typescript-tutorial-exercises/core/graphs/contributors)
[![contributors](https://contrib.rocks/image?repo=type-challenges/site)](https://github.com/type-challenges/site/graphs/contributors)


## License
Expand Down
16 changes: 16 additions & 0 deletions config/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,21 @@
"no_question": {
"en": "No Result",
"zh-CN": "暂无数据"
},
"compilation_error": {
"en": "Compilation Error",
"zh-CN": "编译失败"
},
"compilation_success": {
"en": "Compilation Successful",
"zh-CN": "编译成功"
},
"compilation_success_info": {
"en": "\uD83C\uDF89 Yay! You have finished this challenge.",
"zh-CN": "\uD83C\uDF89 恭喜你完成了这个挑战!"
},
"share_solution": {
"en": "Share your Solution",
"zh-CN": "分享你的解答"
}
}
2 changes: 1 addition & 1 deletion config/links.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"github-repo": "https://github.com/typescript-tutorial-exercises"
"github-repo": "https://github.com/type-challenges/site"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "typescript-tutorial-exercises",
"name": "type-challenges-site",
"version": "1.0.0",
"author": {
"name": "ZLY201",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Footer = function () {
return (
<div className={styles.container}>
<a href={linkJson['github-repo']} target={'_blank'} rel="noreferrer">
copyright © 2023-{dayjs().year()} typescript-tutorial-exercises
copyright © 2023-{dayjs().year()} Type Challenges
</a>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Question/Solution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Solution = function () {

return (
<div className={styles['solution-container']}>
<Skeleton loading={loading} style={{ marginTop: 20 }}>
<Skeleton loading={loading} style={{ marginTop: 20 }} animation={true}>
<Markdown content={solution} theme={theme} />
</Skeleton>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/modules/Results/index.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
border-radius: 8px;
font-size: 16px;
}
.result-accept-btns {
margin-top: 24px;
}
}
.result-accept {
.result-accept-title {
Expand Down
34 changes: 26 additions & 8 deletions src/modules/Results/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { editor } from 'monaco-editor';
import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
import { Skeleton } from '@arco-design/web-react';
import { Button, Skeleton } from '@arco-design/web-react';
import localCache, { QUESTION_STATUS } from '@src/utils/local-cache';
import emitter from '@src/utils/emit';
import Context from '@src/utils/context';
import { monacoEditorLoaded, monacoInstance } from '@src/utils/monaco';
import { QuestionFiles } from '@src/utils/type-challenges';
import SubmitStatus from '@src/components/SubmitStatus';
import i18n from '@config/i18n.json';
import { Setting } from '@src/utils/setting';
import styles from './index.module.less';

function formatErrorFromMarkers(markers: editor.IMarker[]) {
Expand All @@ -17,12 +19,12 @@ function formatErrorFromMarkers(markers: editor.IMarker[]) {
});
}

function createResultError(status: string[]) {
function createResultError(status: string[], language: Setting['language']) {
return (
<div className={styles['result-errors']}>
<div className={styles['result-error-title']}>
<SubmitStatus status={QUESTION_STATUS.unAccepted} />
<span style={{ marginLeft: 8 }}>Compilation Error</span>
<span style={{ marginLeft: 8 }}>{i18n['compilation_error'][language]}</span>
</div>
<div className={styles['result-error-info']}>
{status.map(function (error) {
Expand All @@ -38,29 +40,45 @@ function createResultError(status: string[]) {
}

const Results = function () {
const [{ currentQuestion }] = useContext(Context);
const [{ currentQuestion, setting: { language } }] = useContext(Context);
const [loading, setLoading] = useState(true);
const [status, setStatus] = useState<string[]>([]);

const shareSolutionHref = useMemo(function () {
const questionNum = currentQuestion.match(/[0-9]+(?=-)/)?.[0];
return `https://tsch.js.org/${Number(questionNum)}/answer/${language === 'en' ? '' : language}`;
}, [currentQuestion, language]);

const resultContent = useMemo(
function () {
if (status.length === 0) {
return (
<div className={styles['result-accept']}>
<div className={styles['result-accept-title']}>
<SubmitStatus status={QUESTION_STATUS.accepted} />
<span style={{ marginLeft: 8 }}>Compilation Successful</span>
<span style={{ marginLeft: 8 }}>{i18n['compilation_success'][language]}</span>
</div>
<div className={styles['result-accept-info']}>
🎉 Yay! You have finished this challenge.
{i18n['compilation_success_info'][language]}
</div>
<div className={styles['result-accept-btns']}>
<Button
type={'primary'}
status={'success'}
target={'_blank'}
href={shareSolutionHref}
style={{ borderRadius: 4 }}
>
{i18n['share_solution'][language]}
</Button>
</div>
</div>
);
} else {
return createResultError(status);
return createResultError(status, language);
}
},
[status],
[status, language],
);

const validate = useCallback(
Expand Down
17 changes: 12 additions & 5 deletions src/utils/type-challenges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,39 @@ class TypeChallenges {
}
return this.info || {};
}
async getSolution(cnt: number = 0): Promise<string> {
async getSolution(cnt: number = 3): Promise<string> {
if (this.solution) {
return this.solution;
}
if (cnt === 3) {
if (cnt === 0) {
return 'Get solution failed!';
}
cnt += 1;
const id = this.id;
const index = id.match(/[0-9]+(?=-)/)?.[0];
if (!index) {
return 'Get solution failed!';
}
const controller = new AbortController();
const res = await fetch(
// eslint-disable-next-line max-len
'https://api.github.com/repos/type-challenges/type-challenges/issues?&sort=reactions-+1-desc&per_page=1&labels=answer,' +
String(Number(index)),
String(Number(index)),{
headers: {
Accept: 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28'
},
signal: controller.signal,
}
);
setTimeout(() => controller.abort(), 5000);
try {
const solutions = await res.json();
const solution = solutions?.[0];
const { body, html_url } = solution;
this.solution = `<a href='${html_url}' target='_blank'>${html_url}</a>\n${body}`;
return this.solution;
} catch {
return await this.getSolution(cnt);
return await this.getSolution(cnt - 1);
}
}
}
Expand Down

0 comments on commit 6e3d0a5

Please sign in to comment.