Skip to content

Add code#1

Open
lilspazmin wants to merge 1 commit into
mainfrom
initial-commit
Open

Add code#1
lilspazmin wants to merge 1 commit into
mainfrom
initial-commit

Conversation

@lilspazmin

Copy link
Copy Markdown
Collaborator

Closes #

💸 TL;DR

📜 Details

Design Doc

Jira

🧪 Testing Steps / Validation

✅ Checks

  • CI tests (if present) are passing
  • Adheres to code style for repo
  • Contributor License Agreement (CLA) completed if not a Reddit employee

@stephenoid stephenoid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good. i've left some feedback inline that i hope you will consider. i've tried to avoid repeating comments so please assume they apply everywhere. i think my main concern is all the dependencies this uses. if we could trim this down to be more plain Node.js and TypeScript and not much else, i'd love it ❤️

Comment thread .vscode/settings.json
{
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if you add this, i think you should add an extensions.json to recommend the extension and if we're going to do that, we might want to add eslint with promise linting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i like that you've broken the template into features and even documented how to delete those features. however, the template is so featureful that users are going to either have to delete a substantial part of it to pare it down to their use case or just drag it along. should we trim this to the bare essentials we want to scaffold for users and leave the rest to the docs and examples? not a blocker for me but my preference would be to provide thin templates with clear structure and not much else.

@@ -0,0 +1,29 @@
// Escape regex metacharacters so moderator-entered text is treated literally.
const escapeRegExp = (value: string) =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i suggest adding return types to functions if they're at file scope to clarify and verify intent. this is what we've done for most of the platform.

i also recommend using functions over const since you can order them however you like.

🔕 we'll be able to use RegExp.escape() when we upgrade the backend images.

OnCommentSubmitRequest,
OnPostSubmitRequest,
} from '@devvit/web/shared';
import type { T1, T3 } from '@devvit/shared-types/tid.js';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please drop the shared-types dependency and use @devvit/web/shared only. we're trying to limit Devvit dependencies to devvit and @devvit/web.

// Devvit payload IDs may arrive with or without fullnames.
// These helpers normalize to the typed IDs required by reddit.get*ById methods.
const asT1 = (id: string): T1 => (id.startsWith('t1_') ? id : `t1_${id}`) as T1;
const asT3 = (id: string): T3 => (id.startsWith('t3_') ? id : `t3_${id}`) as T3;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i believe we have these exposed under @devvit/web/shared.

Comment thread src/features/mop/nuke.ts
const shouldRemove = props.remove;
const skipDistinguished = props.skipDistinguished;

try {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please limit the try block to just the parts expected to throw. there's a lot going on in here.

Comment thread src/features/mop/nuke.ts
console.info(
`${comments.length} comment(s) handled in ${timeElapsed} seconds.`
);
} catch (err: unknown) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i believe unknown is the default in the current version of TS.

Comment thread src/features/mop/menu.ts
import type { FormField } from '@devvit/shared-types/shared/form.js';

// Build form fields shown when moderators invoke a Mop action.
export const buildNukeFields = (targetId: string): FormField[] => [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i didn't understand why this was a function.

Comment thread src/features/mop/forms.ts
// Return toast-friendly response for Reddit client.
return {
showToast: `${result.success ? 'Success' : 'Failed'} : ${result.message}`,
} satisfies UiResponse;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this works but i'd prefer we drop the satisfies and just type our return values.

Comment thread src/features/mop/forms.ts
@@ -0,0 +1,102 @@
import type { UiResponse } from '@devvit/web/shared';
import { context } from '@devvit/web/server';
import { isT1, isT3 } from '@devvit/shared-types/tid.js';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please get this from @devvit/web/shared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants