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 AMC Score Calculator extension #62

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 additions & 0 deletions extensions/amc-score-calculator/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"root": true,
"env": {
"es2020": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"]
}
4 changes: 4 additions & 0 deletions extensions/amc-score-calculator/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 120,
"singleQuote": true
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions extensions/amc-score-calculator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "amc-score-calculator",
"title": "AMC Score Calculator",
"description": "Calculates AMC scores for 8, 10, and 12",
"icon": "command-icon.png",
"author": "ryanccn",
"license": "MIT",
"commands": [
{
"name": "eight",
"title": "AMC 8",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"title": "AMC 8",
"title": "Calculate AMC 8 Score",

"subtitle": "",
"description": "Calculate AMC 8 scores",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can provide more detailed description, something like "Get your AMC 8 score from number of correct answers"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same in other two commands

"mode": "view"
},
{
"name": "ten",
"title": "AMC 10",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"title": "AMC 10",
"title": "Calculate AMC 10 Score",

"subtitle": "",
"description": "Calculate AMC 10 scores",
"mode": "view"
},
{
"name": "twelve",
"title": "AMC 12",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"title": "AMC 12",
"title": "Calculate AMC 12 Score",

"subtitle": "",
"description": "Calculate AMC 12 scores",
"mode": "view"
}
],
"dependencies": {
"@raycast/api": "^1.25.0"
},
"devDependencies": {
"@types/node": "~16.10.0",
"@types/react": "^17.0.28",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"typescript": "^4.4.3"
},
"scripts": {
"build": "ray build -e dist",
"dev": "ray develop"
}
}
5 changes: 5 additions & 0 deletions extensions/amc-score-calculator/src/eight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Generic from './generic';

export default () => {
return <Generic title={'AMC 8 Score Calculator'} correctValue={1} emptyValue={0} />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does AMC 8 always returns the same number as number of correct answers? What's the value in this calculation? Or am I missing something?

};
47 changes: 47 additions & 0 deletions extensions/amc-score-calculator/src/generic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Form, ActionPanel, SubmitFormAction, showToast, ToastStyle, Detail, Icon } from '@raycast/api';

interface Props {
title: string;
correctValue: number;
emptyValue: number;
}
interface Values {
c: string;
e: string;
}

const GenericCalculator = (props: Props) => {
const handleSubmit = (values: Values) => {
if (typeof values.c !== 'string' || (props.emptyValue !== 0 && typeof values.e !== 'string')) {
showToast(ToastStyle.Failure, 'Bad Request', "Fields aren't strings");
return;
}

const c = parseInt(values.c);
const e = props.emptyValue !== 0 ? parseInt(values.e) : 0;

if (isNaN(c) || isNaN(e)) {
showToast(ToastStyle.Failure, 'Bad Request', 'Enter numbers, please...');
return;
}

const score = c * props.correctValue + e * props.emptyValue;

showToast(ToastStyle.Success, `Your score is ${score}`, 'Good job!');
};

return (
<Form
actions={
<ActionPanel>
<SubmitFormAction title="Get Score" onSubmit={handleSubmit} icon={Icon.Checkmark} />
</ActionPanel>
}
>
<Form.TextField id="c" title="Correct" placeholder="Number of correct answers" />
{props.emptyValue !== 0 && <Form.TextField id="e" title="Empty" placeholder="Number of questions left empty" />}
</Form>
);
};

export default GenericCalculator;
5 changes: 5 additions & 0 deletions extensions/amc-score-calculator/src/ten.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Generic from './generic';

export default () => {
return <Generic title={'AMC 10 Score Calculator'} correctValue={6} emptyValue={1.5} />;
};
5 changes: 5 additions & 0 deletions extensions/amc-score-calculator/src/twelve.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Generic from './generic';

export default () => {
return <Generic title={'AMC 12 Score Calculator'} correctValue={6} emptyValue={1.5} />;
};
16 changes: 16 additions & 0 deletions extensions/amc-score-calculator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 16",
"include": ["src/**/*"],
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"target": "es2020",
"strict": true,
"isolatedModules": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx"
}
}
Loading