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

[add] Open Source page & model based on MobX-GitHub #218

Merged
merged 5 commits into from
Sep 5, 2024
Merged
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
3 changes: 2 additions & 1 deletion components/Activity/QuestionnairePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ export class QuestionnaireForm extends PureComponent<QuestionnaireFormProps> {
{t('please_complete_all_mandatory_fields_before_you_proceed')}
<a
className="text-primary ms-2"
title={t('edit_profile_tips')}
target="_blank"
href="https://ophapiv2-demo.authing.cn/u"
href="https://github.com/settings/profile"
rel="noreferrer"
>
{t('personal_profile')}
Expand Down
11 changes: 8 additions & 3 deletions components/Git/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GitTemplate } from '@kaiyuanshe/openhackathon-service';
import { GitTemplate, HackathonBase } from '@kaiyuanshe/openhackathon-service';
import { text2color } from 'idea-react';
import { observer } from 'mobx-react';
import { FC, ReactNode } from 'react';
Expand All @@ -9,9 +9,14 @@ import { GitLogo } from './Logo';

const { t } = i18n;

export interface GitCardProps extends GitTemplate {
export type SimpleRepository = Omit<
GitTemplate,
Exclude<keyof HackathonBase, 'id'>
>;

export interface GitCardProps extends SimpleRepository {
className?: string;
renderController?: (item: GitTemplate) => ReactNode;
renderController?: (item: SimpleRepository) => ReactNode;
}

export const GitCard: FC<GitCardProps> = observer(
Expand Down
9 changes: 4 additions & 5 deletions components/PlatformAdmin/PlatformAdminFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Loading } from 'idea-react';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { Fragment, PureComponent } from 'react';
import { Component, Fragment, PropsWithChildren } from 'react';
import { Container, Nav } from 'react-bootstrap';

import { adminMenus } from '../../configuration/menu';
Expand All @@ -25,7 +25,6 @@ import platformAdminStore from '../../models/User/PlatformAdmin';
import { findDeep } from '../../utils/data';
import { MainBreadcrumb } from '../layout/MainBreadcrumb';
import { PageHead } from '../layout/PageHead';
import { ServerSessionBoxProps } from '../User/ServerSessionBox';

const { t } = i18n;

Expand All @@ -43,13 +42,13 @@ library.add(
faDesktop,
);

export interface PlatformAdminFrameProps extends ServerSessionBoxProps {
export type PlatformAdminFrameProps = PropsWithChildren<{
title: string;
path?: string;
}
}>;

@observer
export class PlatformAdminFrame extends PureComponent<PlatformAdminFrameProps> {
export class PlatformAdminFrame extends Component<PlatformAdminFrameProps> {
@observable
accessor loading = false;

Expand Down
33 changes: 0 additions & 33 deletions components/User/AuthingGuard.tsx

This file was deleted.

30 changes: 0 additions & 30 deletions components/User/ServerSessionBox.tsx

This file was deleted.

52 changes: 0 additions & 52 deletions components/User/SessionBox.tsx

This file was deleted.

7 changes: 1 addition & 6 deletions components/layout/MainNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ export const MainNavigation = () => (
>
{t('get_started')}
</Nav.Link>
<Nav.Link
target="_blank"
href="https://github.com/kaiyuanshe/OpenHackathon-Web"
>
{t('open_source_code')}
</Nav.Link>
<Nav.Link href="/open-source">{t('open_source_code')}</Nav.Link>
</Nav>

<UserBar />
Expand Down
2 changes: 1 addition & 1 deletion models/Activity/Award.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User } from '@authing/native-js-ui-components';
import { User } from '@kaiyuanshe/openhackathon-service';
import { Base, Media, Team } from '@kaiyuanshe/openhackathon-service';
import { ListModel, Stream, toggle } from 'mobx-restful';

Expand Down
52 changes: 44 additions & 8 deletions models/Git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'array-unique-proposal';

import { GitTemplate } from '@kaiyuanshe/openhackathon-service';
import { components } from '@octokit/openapi-types';
import { HTTPClient } from 'koajax';
import { githubClient, RepositoryFilter, RepositoryModel } from 'mobx-github';
import { toggle } from 'mobx-restful';

import { TeamWorkModel } from './Activity/Team';
Expand All @@ -9,11 +11,9 @@ import sessionStore from './User/Session';

type Repository = components['schemas']['repository'];

const gitClient = new HTTPClient({
baseURI: 'https://api.github.com/',
responseType: 'json',
}).use(({ request }, next) => {
const { accessToken } = sessionStore.metaOAuth.github || {};
githubClient.use(({ request }, next) => {
const { accessToken = process.env.GITHUB_PAT } =
sessionStore.metaOAuth.github || {};

if (accessToken)
request.headers = {
Expand All @@ -31,7 +31,7 @@ export class GitModel extends TableModel<GitTemplate> {

@toggle('uploading')
async createOneFrom(templateURI: string, name: string) {
const { body } = await gitClient.post<Repository>(
const { body } = await githubClient.post<Repository>(
`repos/${templateURI}/generate`,
{ name },
);
Expand All @@ -40,7 +40,7 @@ export class GitModel extends TableModel<GitTemplate> {

@toggle('uploading')
addCollaborator(URI: string, user: string) {
return gitClient.put(`repos/${URI}/collaborators/${user}`);
return githubClient.put(`repos/${URI}/collaborators/${user}`);
}
}

Expand All @@ -50,3 +50,39 @@ export class WorkspaceModel extends TeamWorkModel {
this.baseURI = `${baseURI}/work/git-repository`;
}
}

export const SourceRepository = [
['kaiyuanshe/open-hackathon'],
[
'kaiyuanshe/OpenHackathon-Web',
'kaiyuanshe/open-hackathon-api',
'kaiyuanshe/open-hackathon-guacamole',
'kaiyuanshe/cloudengine',
],
[
'kaiyuanshe/OpenHackathon-Web',
'kaiyuanshe/OpenHackathon-service',
'kaiyuanshe/OpenHackathon-server',
],
];

export class SourceRepositoryModel extends RepositoryModel {
async loadPage(
page: number,
per_page: number,
{ relation }: RepositoryFilter,
) {
const list = SourceRepository.flat()
.uniqueBy()
.slice((page - 1) * per_page, page * per_page);

const pageData: Awaited<ReturnType<RepositoryModel['getOne']>>[] = [];

for (const full_name of list) {
const item = await this.getOne(full_name, relation);

pageData.push(item);
}
return { pageData, totalCount: list.length };
}
}
2 changes: 1 addition & 1 deletion models/User/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class SessionModel extends BaseModel {

@computed
get metaOAuth() {
const { token } = parseCookie(globalThis.document.cookie);
const { token } = parseCookie(globalThis.document?.cookie || '');

return { github: { accessToken: token } };
}
Expand Down
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
7 changes: 3 additions & 4 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-ignore
import withLess from 'next-with-less';
// @ts-ignore
import setPWA from 'next-pwa';
import WP from 'webpack';

Expand Down Expand Up @@ -44,10 +43,10 @@ const rewrites = async () => ({
});

/** @type {import('next').NextConfig} */
export default withPWA(
withLess({
export default withLess(
withPWA({
reactStrictMode: true,
output: CI && 'standalone',
output: CI ? 'standalone' : undefined,
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
transpilePackages: ['@sentry/browser'],
webpack,
Expand Down
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
"node": ">=20"
},
"dependencies": {
"@authing/native-js-ui-components": "^3.1.31",
"@fortawesome/fontawesome-svg-core": "^6.6.0",
"@fortawesome/free-brands-svg-icons": "^6.6.0",
"@fortawesome/free-regular-svg-icons": "^6.6.0",
"@fortawesome/free-solid-svg-icons": "^6.6.0",
"@fortawesome/react-fontawesome": "^0.2.2",
"@giscus/react": "^3.0.0",
"@sentry/nextjs": "^8.27.0",
"@sentry/nextjs": "^8.28.0",
"array-unique-proposal": "^0.3.4",
"classnames": "^2.5.1",
"echarts-jsx": "^0.5.4",
"idea-react": "^2.0.0-rc.2",
"jsonwebtoken": "^9.0.2",
"koajax": "^2.0.0",
"koajax": "^3.0.2",
"leaflet": "^1.9.4",
"leaflet.chinatmsproviders": "^3.0.6",
"mobx": "^6.13.1",
"mobx-github": "^0.3.4",
"mobx-i18n": "^0.5.0",
"mobx-react": "^9.1.1",
"mobx-react-helper": "^0.3.1",
"mobx-restful": "^0.7.0-rc.0",
"mobx-restful-table": "^2.0.0-rc.1",
"next": "^14.2.7",
"mobx-restful": "^1.0.1",
"mobx-restful-table": "^2.0.0",
"next": "^14.2.8",
"next-ssr-middleware": "^0.8.7",
"open-react-map": "^0.8.0",
"react": "^18.3.1",
Expand All @@ -48,22 +48,27 @@
"@octokit/openapi-types": "^22.2.0",
"@types/jsonwebtoken": "^9.0.6",
"@types/leaflet": "^1.9.12",
"@types/node": "^20.16.2",
"@types/next-pwa": "^5.6.9",
"@types/node": "^20.16.5",
"@types/react": "^18.3.5",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.7",
"eslint-config-next": "^14.2.8",
"eslint-plugin-simple-import-sort": "^12.1.1",
"get-git-folder": "^0.1.2",
"husky": "^9.1.5",
"less": "^4.2.0",
"less-loader": "^12.2.0",
"lint-staged": "^15.2.9",
"lint-staged": "^15.2.10",
"next-pwa": "^5.6.0",
"next-with-less": "^3.0.1",
"prettier": "^3.3.3",
"typescript": "~5.5.4",
"webpack": "^5.94.0"
},
"resolutions": {
"native-file-system-adapter": "npm:@tech_query/[email protected]",
"next": "$next"
},
"prettier": {
"singleQuote": true,
"trailingComma": "all",
Expand Down
Loading
Loading