Skip to content

Commit

Permalink
Migrate to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonmestevao committed Aug 5, 2021
1 parent 3b58b40 commit a9989b4
Show file tree
Hide file tree
Showing 42 changed files with 522 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15.7.0
15.11.0
File renamed without changes.
6 changes: 2 additions & 4 deletions components/Admin/FormsTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ function FormsTable() {
title: 'Link',
editable: false,
width: 300,
dataIndex: 'slug',
render: function UrlLink(slug) {
const link = `${process.env.NEXT_PUBLIC_APP_URL}/f/${slug}`;

dataIndex: 'link',
render: function UrlLink(link) {
return (
<Typography.Link href={link} copyable>
{link}
Expand Down
8 changes: 7 additions & 1 deletion components/Admin/LinksTable/NewLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ function NewLink() {
<QuestionCircleOutlined />
</Tooltip>
</span>
}>
}
rules={[
{
required: true,
message: 'Please select an emoji.'
}
]}>
<Input defaultValue="" placeholder=":emoji:" />
</Item>
<Item
Expand Down
6 changes: 2 additions & 4 deletions components/Admin/LinksTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ const columns = [
title: 'Link',
editable: false,
width: 300,
dataIndex: 'slug',
render: function UrlLink(slug) {
const link = `${process.env.NEXT_PUBLIC_APP_URL}/u/${slug}`;

dataIndex: 'link',
render: function UrlLink(link) {
return (
<Typography.Link href={link} copyable>
{link}
Expand Down
6 changes: 2 additions & 4 deletions components/Admin/RedirectsTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ function RedirectsTable() {
title: 'Link',
editable: false,
width: 300,
dataIndex: 'slug',
render: function UrlLink(slug) {
const link = `${process.env.NEXT_PUBLIC_APP_URL}/r/${slug}`;

dataIndex: 'link',
render: function UrlLink(link) {
return (
<Typography.Link href={link} copyable>
{link}
Expand Down
5 changes: 3 additions & 2 deletions components/Card/index.js → components/Card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Twemoji } from 'react-emoji-render';
import { ILink } from '~/models/Link';

import 'animate.css';
import styles from './style.module.css';

const Card = ({ title, emoji, url, attention }) => (
<a href={url} className={styles.card}>
const Card = ({ title, emoji, link, attention }: ILink) => (
<a href={link} className={styles.card}>
<h3 className={attention ? 'animate__animated animate__shakeX animate__delay-2s' : undefined}>
<Twemoji svg text={`${emoji} ${title}`} />
</h3>
Expand Down
14 changes: 11 additions & 3 deletions components/Footer/index.js → components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
IoHeart
} from 'react-icons/io5';

import social from '~/data/social.yml';
import { domain } from '~/data/settings.json';
import social from '~/data/social.json';

import styles from './style.module.css';
import logo from '../../public/cesium.svg';
Expand All @@ -19,7 +20,14 @@ const logos = {
github: IoLogoGithub
};

const SocialIcon = ({ name, url, username, tag }) => {
interface SocialIconProps {
name: string;
url: string;
username: string;
tag: string;
}

const SocialIcon = ({ name, url, username, tag }: SocialIconProps) => {
const Icon = logos[tag];

return (
Expand All @@ -37,7 +45,7 @@ const Footer = () => (
))}
</div>
<div className={styles.copyright}>
<a href="https://cesium.di.uminho.pt" target="_blank" rel="noopener noreferrer">
<a href={domain} target="_blank" rel="noopener noreferrer">
hacked with <IoHeart className={styles.heart} size="1.2em" /> by
<Image width={84} height={24} src={logo} alt="CeSIUM's Logo" />
</a>
Expand Down
11 changes: 11 additions & 0 deletions data/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"domain": "https://cesium.di.uminho.pt",
"github": {
"base_url": "https://github.com",
"username": "cesium"
},
"gitlab": {
"base_url": "https://gitlab.com",
"username": "cesiuminho"
}
}
9 changes: 0 additions & 9 deletions data/settings.yml

This file was deleted.

29 changes: 29 additions & 0 deletions data/social.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"name": "Facebook",
"tag": "facebook",
"url": "https://facebook.com",
"username": "cesiuminho"
},

{
"name": "Instagram",
"tag": "instagram",
"url": "https://instagram.com",
"username": "cesiuminho"
},

{
"name": "Twitter",
"tag": "twitter",
"url": "https://twitter.com",
"username": "cesiuminho"
},

{
"name": "GitHub",
"tag": "github",
"url": "https://github.com",
"username": "cesium"
}
]
19 changes: 0 additions & 19 deletions data/social.yml

This file was deleted.

5 changes: 4 additions & 1 deletion hooks/useAsyncReducer.js → hooks/useAsyncReducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useState } from 'react';

export default function useAsyncReducer(reducer, initState) {
export default function useAsyncReducer(
reducer: (state: unknown, action: string) => Promise<unknown>,
initState: unknown
) {
const [state, setState] = useState(initState);
const dispatchState = async (action) => setState(await reducer(state, action));
return [state, dispatchState];
Expand Down
14 changes: 0 additions & 14 deletions jsconfig.json

This file was deleted.

File renamed without changes.
File renamed without changes.
12 changes: 0 additions & 12 deletions models/Form.js

This file was deleted.

33 changes: 33 additions & 0 deletions models/Form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import mongoose, { Schema } from 'mongoose';

export interface IForm {
_id: string;
name: string;
slug: string;
url: string;
link: string;
visits: number;
created: Date;
updated: Date;
}

const Form = new Schema<IForm>(
{
name: { type: String, required: true },
slug: { type: String, unique: true, index: true, required: true },
url: { type: String, required: true },
visits: { type: Number, default: 0 },
created: { type: Date, default: Date.now },
updated: { type: Date, default: Date.now }
},
{
toJSON: { virtuals: true },
toObject: { virtuals: true }
}
);

Form.virtual('link').get(function () {
return `${process.env.NEXT_PUBLIC_APP_URL}/f/${this.slug}`;
});

export default mongoose.models.Form || mongoose.model('Form', Form);
15 changes: 0 additions & 15 deletions models/Link.js

This file was deleted.

38 changes: 38 additions & 0 deletions models/Link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import mongoose, { Schema } from 'mongoose';
import { nanoid } from 'nanoid';

export interface ILink {
_id: string;
title: string;
url: string;
emoji: string;
attention: boolean;
index: number;
slug: string;
link: string;
clicks: number;
created: Date;
}

const Link = new Schema<ILink>(
{
title: { type: String, required: true },
url: { type: String, required: true },
emoji: { type: String, required: true },
attention: { type: Boolean, default: false },
index: { type: Number, required: true, index: true },
slug: { type: String, unique: true, index: true, required: true, default: () => nanoid(10) },
clicks: { type: Number, default: 0 },
created: { type: Date, default: Date.now }
},
{
toJSON: { virtuals: true },
toObject: { virtuals: true }
}
);

Link.virtual('link').get(function () {
return `${process.env.NEXT_PUBLIC_APP_URL}/u/${this.slug}`;
});

export default mongoose.models.Link || mongoose.model('Link', Link);
13 changes: 0 additions & 13 deletions models/Redirect.js

This file was deleted.

34 changes: 34 additions & 0 deletions models/Redirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import mongoose, { Schema } from 'mongoose';
import { nanoid } from 'nanoid';

export interface IRedirect {
_id: string;
name: string;
slug: string;
url: string;
link: string;
visits: number;
created: Date;
updated: Date;
}

const Redirect = new Schema<IRedirect>(
{
name: { type: String, required: true },
slug: { type: String, unique: true, index: true, required: true, default: () => nanoid(5) },
url: { type: String, required: true },
visits: { type: Number, default: 0 },
created: { type: Date, default: Date.now },
updated: { type: Date, default: Date.now }
},
{
toJSON: { virtuals: true },
toObject: { virtuals: true }
}
);

Redirect.virtual('link').get(function () {
return `${process.env.NEXT_PUBLIC_APP_URL}/r/${this.slug}`;
});

export default mongoose.models.Redirect || mongoose.model('Redirect', Redirect);
3 changes: 3 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />
5 changes: 0 additions & 5 deletions next.config.js

This file was deleted.

Loading

0 comments on commit a9989b4

Please sign in to comment.