Created
June 5, 2021 00:32
-
-
Save guzmonne/eb3ac8795117edfdbd49130cf7df5107 to your computer and use it in GitHub Desktop.
Created from Remix Form!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { redirect } from "remix" | |
import type { ActionFunction } from "remix" | |
export const action: ActionFunction = async ({ request }) => { | |
const token = "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" | |
const body = new URLSearchParams(await request.text()) | |
const fileName = body.get("fileName") as string | |
const content = body.get("content") | |
await fetch("https://api.github.com/gists", { | |
method: "post", | |
body: JSON.stringify({ | |
description: "Created from Remix Form!", | |
public: true, | |
files: {[fileName]: {content}}, | |
}), | |
headers: { | |
"Content-Type": "application/json", | |
"Authorization": `token ${token}` | |
} | |
}) | |
return redirect("/gists") | |
} | |
export default function NewGist() { | |
return ( | |
<React.Fragment> | |
<h2>New Gist!</h2> | |
<form method="post"> | |
<p> | |
<label> | |
Gist file name: | |
<br /> | |
<input required type="text" name="fileName" /> | |
</label> | |
</p> | |
<p> | |
<label> | |
Content: | |
<br /> | |
<textarea required rows={10} name="content" /> | |
</label> | |
</p> | |
<p> | |
<button type="submit">Create Gist</button> | |
</p> | |
</form> | |
</React.Fragment> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment