Skip to content

Commit baabe52

Browse files
authored
Update code snippets to 0.13.4 (#145)
Updates code snippets to match latest `0.13.4` API for future consistency, alongside minor correctness fixes.
1 parent 882381a commit baabe52

12 files changed

Lines changed: 33 additions & 54 deletions

File tree

docs/capabilities/creating_custom_post.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ await reddit.submitCustomPost({
7676
"backgroundColor": "#FFFFFFFF", // white, fully opaque
7777
"backgroundColorDark": "#000000FF", // black, fully opaque
7878
"height": "TALL",
79-
"shareImageUrl": "https://reddi.it/12345.png"
79+
"shareImageUrl": "https://i.redd.it/o0h58lzmax6a1.png"
8080
}
8181
})
8282
```
@@ -90,9 +90,7 @@ Use `post.setCustomPostStyles()` to update styles on an existing post. Only inc
9090
```javascript
9191
const post = await reddit.getPostById(context.postId);
9292
await post.setCustomPostStyles({
93-
"styles": {
94-
"shareImageUrl": "https://example.com/new-preview.png"
95-
}
93+
"shareImageUrl": "https://i.redd.it/o0h58lzmax6a1.png"
9694
});
9795
```
9896

docs/capabilities/server/reddit-api.mdx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,11 @@ Auto-comments should be used to spark conversation in the post comments, but you
9090

9191

9292
```ts
93-
import { context, reddit } from '@devvit/web/server';
93+
import { reddit } from '@devvit/web/server';
9494

9595
export const createComment = async () => {
96-
const { subredditName } = context;
97-
if (!subredditName) {
98-
throw new Error('subredditName is required');
99-
}
100-
101-
reddit.submitComment({
102-
postId: 't3_123456', // Replace with the actual post ID
96+
return await reddit.submitComment({
97+
id: 't3_123456', // Replace with the actual post ID
10398
text: 'This is a comment from a Devvit app',
10499
runAs: 'USER' // Optional: specify the user to run as
105100
});

docs/capabilities/server/userActions.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ If `runAs` is not specified, the API will use `runAs: 'APP'` by default.
6969
| Parameter | Description |
7070
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |
7171
| `runAs` | The type of account to perform the action on behalf of: `'USER'` or `'APP'`. Defaults to `'APP'`. |
72-
| `userGeneratedContent` | Text or images submitted by the user. Required for `submitPost()` with `runAs: 'USER'` for safety and compliance review. |
72+
| `userGeneratedContent` | Text or images submitted by the user. Required for `submitCustomPost()` with `runAs: 'USER'` for safety and compliance review. |
7373

7474
### Differences during playtesting
7575

@@ -96,7 +96,7 @@ Your app version needs to be approved in order for user actions to be enabled fo
9696
<TabItem value="hono">
9797

9898
```tsx title="server/index.ts"
99-
import { reddit } from '@devvit/web/server';
99+
import { context, reddit } from '@devvit/web/server';
100100

101101
// ...
102102

@@ -106,7 +106,7 @@ app.post('/internal/post-create', async (c) => {
106106
return c.json({ status: 'error', message: 'subredditName is required' }, 400);
107107
}
108108

109-
reddit.submitPost({
109+
await reddit.submitCustomPost({
110110
runAs: 'USER',
111111
userGeneratedContent: {
112112
text: "Hello there! This is a new post from the user's account",
@@ -124,7 +124,7 @@ app.post('/internal/post-create', async (c) => {
124124
<TabItem value="express">
125125

126126
```tsx title="server/index.ts"
127-
import { reddit } from '@devvit/web/server';
127+
import { context, reddit } from '@devvit/web/server';
128128

129129
// ...
130130

@@ -135,7 +135,7 @@ router.post('/internal/post-create', async (_req, res) => {
135135
return;
136136
}
137137

138-
reddit.submitPost({
138+
await reddit.submitCustomPost({
139139
runAs: 'USER',
140140
userGeneratedContent: {
141141
text: "Hello there! This is a new post from the user's account",

docs/guides/migrate/public-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ const { postId } = context;
312312
if (!postId) throw new Error("Run on a post.");
313313

314314
const pinned = await reddit.submitComment({
315-
postId,
315+
id: postId,
316316
text: "Pinned notice.",
317317
runAs: "APP",
318318
});

versioned_docs/version-0.12/capabilities/creating_custom_post.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ await reddit.submitCustomPost({
7676
"backgroundColor": "#FFFFFFFF", // white, fully opaque
7777
"backgroundColorDark": "#000000FF", // black, fully opaque
7878
"height": "TALL",
79-
"shareImageUrl": "https://reddi.it/12345.png"
79+
"shareImageUrl": "https://i.redd.it/o0h58lzmax6a1.png"
8080
}
8181
})
8282
```
@@ -90,9 +90,7 @@ Use `post.setCustomPostStyles()` to update styles on an existing post. Only inc
9090
```javascript
9191
const post = await reddit.getPostById(context.postId);
9292
await post.setCustomPostStyles({
93-
"styles": {
94-
"shareImageUrl": "https://example.com/new-preview.png"
95-
}
93+
"shareImageUrl": "https://i.redd.it/o0h58lzmax6a1.png"
9694
});
9795
```
9896

versioned_docs/version-0.12/capabilities/server/reddit-api.mdx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,11 @@ Auto-comments should be used to spark conversation in the post comments, but you
9090

9191

9292
```ts
93-
import { context, reddit } from '@devvit/web/server';
93+
import { reddit } from '@devvit/web/server';
9494

9595
export const createComment = async () => {
96-
const { subredditName } = context;
97-
if (!subredditName) {
98-
throw new Error('subredditName is required');
99-
}
100-
101-
reddit.submitComment({
102-
postId: 't3_123456', // Replace with the actual post ID
96+
return await reddit.submitComment({
97+
id: 't3_123456', // Replace with the actual post ID
10398
text: 'This is a comment from a Devvit app',
10499
runAs: 'USER' // Optional: specify the user to run as
105100
});

versioned_docs/version-0.12/capabilities/server/userActions.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ If `runAs` is not specified, the API will use `runAs: 'APP'` by default.
6969
| Parameter | Description |
7070
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |
7171
| `runAs` | The type of account to perform the action on behalf of: `'USER'` or `'APP'`. Defaults to `'APP'`. |
72-
| `userGeneratedContent` | Text or images submitted by the user. Required for `submitPost()` with `runAs: 'USER'` for safety and compliance review. |
72+
| `userGeneratedContent` | Text or images submitted by the user. Required for `submitCustomPost()` with `runAs: 'USER'` for safety and compliance review. |
7373

7474
### Differences during playtesting
7575

@@ -96,7 +96,7 @@ Your app version needs to be approved in order for user actions to be enabled fo
9696
<TabItem value="hono">
9797

9898
```tsx title="server/index.ts"
99-
import { reddit } from '@devvit/web/server';
99+
import { context, reddit } from '@devvit/web/server';
100100

101101
// ...
102102

@@ -106,7 +106,7 @@ app.post('/internal/post-create', async (c) => {
106106
return c.json({ status: 'error', message: 'subredditName is required' }, 400);
107107
}
108108

109-
reddit.submitPost({
109+
await reddit.submitCustomPost({
110110
runAs: 'USER',
111111
userGeneratedContent: {
112112
text: "Hello there! This is a new post from the user's account",
@@ -124,7 +124,7 @@ app.post('/internal/post-create', async (c) => {
124124
<TabItem value="express">
125125

126126
```tsx title="server/index.ts"
127-
import { reddit } from '@devvit/web/server';
127+
import { context, reddit } from '@devvit/web/server';
128128

129129
// ...
130130

@@ -135,7 +135,7 @@ router.post('/internal/post-create', async (_req, res) => {
135135
return;
136136
}
137137

138-
reddit.submitPost({
138+
await reddit.submitCustomPost({
139139
runAs: 'USER',
140140
userGeneratedContent: {
141141
text: "Hello there! This is a new post from the user's account",

versioned_docs/version-0.12/guides/migrate/public-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ const { postId } = context;
312312
if (!postId) throw new Error("Run on a post.");
313313

314314
const pinned = await reddit.submitComment({
315-
postId,
315+
id: postId,
316316
text: "Pinned notice.",
317317
runAs: "APP",
318318
});

versioned_docs/version-0.13/capabilities/creating_custom_post.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ await reddit.submitCustomPost({
7676
"backgroundColor": "#FFFFFFFF", // white, fully opaque
7777
"backgroundColorDark": "#000000FF", // black, fully opaque
7878
"height": "TALL",
79-
"shareImageUrl": "https://reddi.it/12345.png"
79+
"shareImageUrl": "https://i.redd.it/o0h58lzmax6a1.png"
8080
}
8181
})
8282
```
@@ -90,9 +90,7 @@ Use `post.setCustomPostStyles()` to update styles on an existing post. Only inc
9090
```javascript
9191
const post = await reddit.getPostById(context.postId);
9292
await post.setCustomPostStyles({
93-
"styles": {
94-
"shareImageUrl": "https://example.com/new-preview.png"
95-
}
93+
"shareImageUrl": "https://i.redd.it/o0h58lzmax6a1.png"
9694
});
9795
```
9896

versioned_docs/version-0.13/capabilities/server/reddit-api.mdx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,11 @@ Auto-comments should be used to spark conversation in the post comments, but you
9090

9191

9292
```ts
93-
import { context, reddit } from '@devvit/web/server';
93+
import { reddit } from '@devvit/web/server';
9494

9595
export const createComment = async () => {
96-
const { subredditName } = context;
97-
if (!subredditName) {
98-
throw new Error('subredditName is required');
99-
}
100-
101-
reddit.submitComment({
102-
postId: 't3_123456', // Replace with the actual post ID
96+
return await reddit.submitComment({
97+
id: 't3_123456', // Replace with the actual post ID
10398
text: 'This is a comment from a Devvit app',
10499
runAs: 'USER' // Optional: specify the user to run as
105100
});

0 commit comments

Comments
 (0)