Skip to content

Commit

Permalink
Merge branch 'canary' into add-core-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flybayer committed Mar 2, 2020
2 parents 3270c72 + c48fd89 commit 39fb911
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners

* @flybayer
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

# github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
# patreon: # Replace with a single Patreon username
patreon: flybayer
open_collective: blitzjs
custom: ['https://paypal.me/thebayers?locale.x=en_US']
custom: ['https://paypal.me/thebayers']
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ The initial Blitz demo is live at [first-demo.blitzjs.com](https://first-demo.bl

It's source code is at [examples/first-demo](https://github.com/blitz-js/blitz/blob/canary/examples/first-demo). NOTE: The API is very alpha, and will change.

## Sponsors

_Sponsor Blitz and display your logo and hiring status here. [See options on Open Collective](https://opencollective.com/blitzjs)_

## I invite you to join me — let’s build the future of web dev together. 🤝

If you’re interested in helping or just want to keep a pulse on the project, [drop your email here 👉 Blitzjs.com](https://blitzjs.com)
Expand Down
6 changes: 3 additions & 3 deletions examples/first-demo/controllers/comments.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Controller} from '@blitzjs/core'
import alex from 'alex'
import {validContent} from '../utils/contentFilter'

export const CommentsController = Controller(({db}) => ({
name: 'CommentsController',

permit: ['content'],

async create(params, newData) {
if (alex(newData.content).messages.length || newData.content?.toLowerCase().includes('4chan')) {
newData.content = 'Be nice'
if (!validContent(newData.content)) {
newData.content = 'Fruit'
}

const data = await db.comment.create({
Expand Down
20 changes: 10 additions & 10 deletions examples/first-demo/controllers/posts.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Controller} from '@blitzjs/core'
import alex from 'alex'
import {validContent} from '../utils/contentFilter'

export const PostsController = Controller(({db}) => ({
name: 'PostsController',

permit: ['title', 'content'],

async index() {
const posts = await db.post.findMany({orderBy: {id: 'asc'}})
const posts = await db.post.findMany({orderBy: {id: 'desc'}, first: 20})

return {
data: {posts},
Expand All @@ -23,11 +23,11 @@ export const PostsController = Controller(({db}) => ({
},

async create(params, newData) {
if (alex(newData.title).messages.length || newData.title?.toLowerCase().includes('4chan')) {
newData.title = 'Be nice'
if (!validContent(newData.title)) {
newData.title = 'Fruit'
}
if (alex(newData.content).messages.length || newData.content?.toLowerCase().includes('4chan')) {
newData.content = 'Be nice'
if (!validContent(newData.content)) {
newData.content = 'Fruit'
}

const data = await db.post.create({
Expand All @@ -44,11 +44,11 @@ export const PostsController = Controller(({db}) => ({
},

async update(params, newData) {
if (alex(newData.title).messages.length || newData.title?.toLowerCase().includes('4chan')) {
newData.title = 'Be nice'
if (!validContent(newData.title)) {
newData.title = 'Fruit'
}
if (alex(newData.content).messages.length || newData.content?.toLowerCase().includes('4chan')) {
newData.content = 'Be nice'
if (!validContent(newData.content)) {
newData.content = 'Fruit'
}

const data = await db.post.update({
Expand Down
2 changes: 2 additions & 0 deletions examples/first-demo/pages/posts/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function Page({post}) {
</button>
</div>
</Form>

<p className="py-3">For your safety, content can only be the name of a fruit</p>
</div>
)
}
2 changes: 2 additions & 0 deletions examples/first-demo/pages/posts/[id]/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function Page({post}) {

<h1 className="text-3xl">{post.title}</h1>

<p className="py-3">For your safety, content can only be the name of a fruit</p>

<Form action={`/api/posts/${post.id}`} method="PATCH" className="min-w-full">
<div className="mb-4">
<label className="block text-gray-700 text-sm font-bold mb-2">Title</label>
Expand Down
2 changes: 1 addition & 1 deletion examples/first-demo/pages/posts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Page({posts}) {
</a>
</p>

<h1 className="text-3xl">{posts.length} Posts</h1>
<h1 className="text-3xl">First {posts.length} Posts</h1>
<p className="mt-5">
<Link href="/">
<a className="underline text-purple-700 text-sm">Back Home</a>
Expand Down
2 changes: 2 additions & 0 deletions examples/first-demo/pages/posts/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function Page() {

<h1 className="text-3xl">New Post</h1>

<p className="py-3">For your safety, content can only be the name of a fruit</p>

<Form action={`/api/posts`} method="POST" className="min-w-full">
<div className="mb-4">
<label className="block text-gray-700 text-sm font-bold mb-2">Title</label>
Expand Down
34 changes: 34 additions & 0 deletions examples/first-demo/utils/contentFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fruits = [
'Apple',
'Watermelon',
'Orange',
'Pear',
'Cherry',
'Strawberry',
'Nectarine',
'Grape',
'Mango',
'Blueberry',
'Pomegranate',
'Plum',
'Banana',
'Raspberry',
'Mandarin',
'Jackfruit',
'Papaya',
'Kiwi',
'Pineapple',
'Lime',
'Lemon',
'Apricot',
'Grapefruit',
'Melon',
'Coconut',
'Peach',
'Tomato',
].map(f => f.toLowerCase())

export function validContent(str?: string) {
if (!str) return true
return fruits.includes(str.toLowerCase().trim())
}

0 comments on commit 39fb911

Please sign in to comment.