Skip to content

Commit

Permalink
[Lorem-Ipsum] Visual Improvements for prompts and command arguments (#…
Browse files Browse the repository at this point in the history
…13439)

* perf(lorem-ipsum): visual improvements and fail fast for AI

* refactor(lorem-ipsum): lint fixes

* fix(lorem-ipsum): fixed the clipboard.paste

* refactor(lorem-ipsum): showError utility

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: raycastbot <bot@raycast.com>
  • Loading branch information
jfkisafk and raycastbot committed Jul 12, 2024
1 parent 118f6f8 commit a219790
Show file tree
Hide file tree
Showing 11 changed files with 1,123 additions and 2,524 deletions.
8 changes: 1 addition & 7 deletions extensions/lorem-ipsum/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"root": true,
"env": {
"es2020": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"]
"extends": ["@raycast"]
}
6 changes: 6 additions & 0 deletions extensions/lorem-ipsum/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Lorem Ipsum Changelog

## [Improvements] - 2024-07-12

- Replaced HUDs with Toasts (after closing the window) for color coding prompts
- Fail-fast AI generation in case user doesn't have access to AI
- Made command argument placeholders more meaningful

## [New PRO Feature] - 2023-11-21

- Added Generate with AI command.
Expand Down
3,514 changes: 1,057 additions & 2,457 deletions extensions/lorem-ipsum/package-lock.json

Large diffs are not rendered by default.

37 changes: 20 additions & 17 deletions extensions/lorem-ipsum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"license": "MIT",
"contributors": [
"GastroGeek",
"stelo",
"enkia"
],
"categories": [
Expand All @@ -34,10 +35,10 @@
"mode": "no-view",
"arguments": [
{
"name": "numberOfLoremIpsumsToGenerate",
"name": "numberOfParagraphs",
"type": "text",
"required": false,
"placeholder": "1"
"placeholder": "No. of paragraphs"
}
]
},
Expand All @@ -49,10 +50,10 @@
"mode": "no-view",
"arguments": [
{
"name": "numberOfLoremIpsumsToGenerate",
"name": "numberOfSentences",
"type": "text",
"required": false,
"placeholder": "1"
"placeholder": "No. of sentences"
}
]
},
Expand All @@ -64,10 +65,10 @@
"mode": "no-view",
"arguments": [
{
"name": "numberOfLoremIpsumsToGenerate",
"name": "numberOfWords",
"type": "text",
"required": false,
"placeholder": "1"
"placeholder": "No. of words"
}
]
},
Expand Down Expand Up @@ -107,22 +108,24 @@
}
],
"dependencies": {
"@raycast/api": "^1.61.2",
"@raycast/api": "^1.78.1",
"lorem-ipsum": "^2.0.8",
"node-fetch": "^3.2.10"
"node-fetch": "^3.3.2"
},
"devDependencies": {
"@types/node": "^18.7.21",
"@types/react": "^18.0.21",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"react-devtools": "^4.26.0",
"typescript": "^4.8.3"
"@raycast/eslint-config": "^1.0.8",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"typescript": "^5.5.3"
},
"scripts": {
"build": "ray build -e dist",
"dev": "ray develop"
"dev": "ray develop",
"fix-lint": "ray lint --fix",
"lint": "ray lint"
}
}
19 changes: 9 additions & 10 deletions extensions/lorem-ipsum/src/ai-generate.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AI, showToast, Toast } from "@raycast/api";
import { produceOutput } from "./utils";
import { AI, environment, LaunchProps, showToast, Toast } from "@raycast/api";
import { showError, produceOutput } from "./utils";

function constructPrompt(topic: string | undefined) {
const topicInstructions = topic
? `The topic you should write about is "${topic}".`
: `Pick a completely random topic to write about. Just make sure all paragraphs are about that topic.`;
const prompt = `
return `
You are only capable of outputting a series of paragraphs. What follows is a set of rules I'd like you to adhere to:
- separate paragraphs with a blank line, nothing else
- do not write in first person
Expand All @@ -14,15 +14,14 @@ function constructPrompt(topic: string | undefined) {
Generate between two and five short paragraphs. ${topicInstructions}
`;

return prompt;
}

export default async function AICommand(props?: {
arguments: {
topic: string;
};
}) {
export default async function AICommand(props?: LaunchProps<{ arguments: Arguments.AiGenerate }>) {
if (!environment.canAccess(AI)) {
await showError("You don't have access to AI.");
return;
}

const topic = props?.arguments.topic || undefined;
const isRandom = topic === undefined;

Expand Down
11 changes: 5 additions & 6 deletions extensions/lorem-ipsum/src/paragraphs.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { showHUD } from "@raycast/api";
import { generateParagraphs, produceOutput, safeLoremIpsumNumberArg } from "./utils";
import { LoremIpsumArguments } from "./types";
import { LaunchProps } from "@raycast/api";
import { generateParagraphs, showError, produceOutput, safeLoremIpsumNumberArg } from "./utils";

export default async function ParagraphCommand(props?: { arguments: LoremIpsumArguments }) {
const numberArg = props?.arguments.numberOfLoremIpsumsToGenerate;
export default async function ParagraphCommand(props?: LaunchProps<{ arguments: Arguments.Paragraphs }>) {
const numberArg = props?.arguments.numberOfParagraphs;

const { error, safeLoremIpsumNumber } = await safeLoremIpsumNumberArg(numberArg);

if (error) {
await showHUD(`❌ ${error.message}`);
await showError(error.message);
} else {
const output = generateParagraphs(safeLoremIpsumNumber);
await produceOutput(output);
Expand Down
11 changes: 5 additions & 6 deletions extensions/lorem-ipsum/src/sentences.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { showHUD } from "@raycast/api";
import { generateSentences, produceOutput, safeLoremIpsumNumberArg } from "./utils";
import { LoremIpsumArguments } from "./types";
import { LaunchProps } from "@raycast/api";
import { generateSentences, showError, produceOutput, safeLoremIpsumNumberArg } from "./utils";

export default async function SentenceCommand(props?: { arguments: LoremIpsumArguments }) {
const numberArg = props?.arguments.numberOfLoremIpsumsToGenerate;
export default async function SentenceCommand(props?: LaunchProps<{ arguments: Arguments.Sentences }>) {
const numberArg = props?.arguments.numberOfSentences;

const { error, safeLoremIpsumNumber } = await safeLoremIpsumNumberArg(numberArg);

if (error) {
await showHUD(`❌ ${error.message}`);
await showError(error.message);
} else {
const output = generateSentences(safeLoremIpsumNumber);
await produceOutput(output);
Expand Down
5 changes: 0 additions & 5 deletions extensions/lorem-ipsum/src/types.tsx

This file was deleted.

15 changes: 10 additions & 5 deletions extensions/lorem-ipsum/src/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { closeMainWindow, Clipboard, showHUD, getPreferenceValues } from "@raycast/api";
import { closeMainWindow, Clipboard, getPreferenceValues, showToast, Toast } from "@raycast/api";
import { LoremIpsum } from "lorem-ipsum";

// don't want to cause a heap error, so cap it 😱
Expand Down Expand Up @@ -72,20 +72,25 @@ export const safeLoremIpsumNumberArg = async (arg: string | undefined) => {
}
};

export const showError = async (msg: string) => {
await closeMainWindow();
await showToast(Toast.Style.Failure, msg);
};

export const produceOutput = async (content: string) => {
const { action: preference = "clipboard" } = getPreferenceValues();

await closeMainWindow();

switch (preference) {
case "clipboard":
await Clipboard.copy(content);
showHUD("Copied to clipboard! 📋");
await showToast(Toast.Style.Success, "Copied to clipboard! 📋");
break;

case "paste":
await Clipboard.paste(content);
showHUD("Pasted to active app! 📝");
await showToast(Toast.Style.Success, "Pasted to active app! 📝");
break;
}

await closeMainWindow();
};
11 changes: 5 additions & 6 deletions extensions/lorem-ipsum/src/words.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { showHUD } from "@raycast/api";
import { generateWords, produceOutput, safeLoremIpsumNumberArg } from "./utils";
import { LoremIpsumArguments } from "./types";
import { LaunchProps } from "@raycast/api";
import { generateWords, showError, produceOutput, safeLoremIpsumNumberArg } from "./utils";

export default async function WordCommand(props?: { arguments: LoremIpsumArguments }) {
const numberArg = props?.arguments.numberOfLoremIpsumsToGenerate;
export default async function WordCommand(props?: LaunchProps<{ arguments: Arguments.Words }>) {
const numberArg = props?.arguments.numberOfWords;

const { error, safeLoremIpsumNumber } = await safeLoremIpsumNumberArg(numberArg);

if (error) {
await showHUD(`❌ ${error.message}`);
await showError(error.message);
} else {
const output = generateWords(safeLoremIpsumNumber);
await produceOutput(output);
Expand Down
10 changes: 5 additions & 5 deletions extensions/lorem-ipsum/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 16",
"include": ["src/**/*"],
"include": ["src/**/*", "raycast-env.d.ts"],
"compilerOptions": {
"lib": ["es2020"],
"lib": ["ES2023"],
"module": "commonjs",
"target": "es2020",
"target": "ES2022",
"strict": true,
"isolatedModules": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx"
"jsx": "react-jsx",
"resolveJsonModule": true,
}
}

0 comments on commit a219790

Please sign in to comment.