Initial commit

This commit is contained in:
Bradley Shellnut 2022-04-01 19:30:11 -07:00
commit 4b3499ca1e
25 changed files with 2469 additions and 0 deletions

20
.eslintrc.cjs Normal file
View file

@ -0,0 +1,20 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['*.cjs'],
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
settings: {
'svelte3/typescript': () => require('typescript')
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020
},
env: {
browser: true,
es2017: true,
node: true
}
};

9
.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
dev.db

1
.npmrc Normal file
View file

@ -0,0 +1 @@
engine-strict=true

7
.prettierrc Normal file
View file

@ -0,0 +1,7 @@
{
"semi": false,
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 60
}

40
README.md Normal file
View file

@ -0,0 +1,40 @@
# create-svelte
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```bash
# create a new project in the current directory
npm init svelte@next
# create a new project in my-app
npm init svelte@next my-app
```
> Note: the `@next` is temporary
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```bash
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```bash
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.

40
package.json Normal file
View file

@ -0,0 +1,40 @@
{
"name": "tutorial",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"package": "svelte-kit package",
"preview": "svelte-kit preview",
"prepare": "svelte-kit sync",
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
},
"prisma": {
"seed": "node --loader ts-node/esm prisma/seed.ts"
},
"devDependencies": {
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "next",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-svelte3": "^3.2.1",
"prettier": "^2.5.1",
"prettier-plugin-svelte": "^2.5.0",
"svelte": "^3.44.0",
"svelte-check": "^2.2.6",
"svelte-preprocess": "^4.10.1",
"ts-node": "^10.7.0",
"tslib": "^2.3.1",
"typescript": "~4.6.2"
},
"type": "module",
"dependencies": {
"@prisma/client": "^3.11.1"
}
}

1914
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff

36
prisma/schema.prisma Normal file
View file

@ -0,0 +1,36 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model Tweet {
id Int @id @default(autoincrement())
url String
posted DateTime
content String
likes Int
user User @relation(fields: [userId], references: [id])
userId Int
}
model User {
id Int @id @default(autoincrement())
email String @unique
handle String @unique
name String
avatar String
about String
tweets Tweet[]
liked Liked[]
}
model Liked {
id Int @id @default(autoincrement())
tweetId Int @unique
user User @relation(fields: [userId], references: [id])
userId Int
}

110
prisma/seed.ts Normal file
View file

@ -0,0 +1,110 @@
import PrismaClientPkg from '@prisma/client'
// Prisma doesn't support ES Modules so we have to do this
const PrismaClient = PrismaClientPkg.PrismaClient
const prisma = new PrismaClient()
export function randomUrl(): string {
return Math.random().toString(16).slice(2)
}
// gets random time starting from now and
// going back one day whenever you seed the
// database in the future
export function randomDate(): string {
// this is set to one day
const offset = 24 * 60 * 60 * 1000 * 1
const current = new Date().getTime()
const random = Math.random() * offset
const difference = new Date(current - random)
return difference.toISOString()
}
function getUsers() {
return [
{
name: 'matia',
handle: '@joyofcodedev',
email: 'matia@example.test',
avatar: '/profile/matia/avatar.webp',
about: 'Likes long walks on the beach. 😘',
tweets: {
create: [
{
url: randomUrl(),
posted: randomDate(),
content: `SvelteKit is lit. 🔥`,
likes: 10
},
{
url: randomUrl(),
posted: randomDate(),
content: `I love Svelte! ❤️`,
likes: 24
},
{
url: randomUrl(),
posted: randomDate(),
content: `Sometimes when I'm writing JavaScript I want to throw up my hands and say "this is crazy!" but I can't remember what "this" refers to. 🤪`,
likes: 0
},
{
url: randomUrl(),
posted: randomDate(),
content: `How do you comfort a JavaScript bug? You console it. 🤭`,
likes: 0
}
]
}
},
{
name: 'bob',
handle: '@bobross',
email: 'bob@example.test',
avatar: '/profile/bob/avatar.webp',
about: 'Likes painting.',
tweets: {
create: [
{
url: randomUrl(),
posted: randomDate(),
content: `Use your imagination. Wind it up, blend it together. The joy of painting really is universal.`,
likes: 1
},
{
url: randomUrl(),
posted: randomDate(),
content: `The only thing I have control over is taking out the trash. 😂`,
likes: 4
},
{
url: randomUrl(),
posted: randomDate(),
content:
'Painting is as individual as people are. 👩‍🎨',
likes: 0
},
{
url: randomUrl(),
posted: randomDate(),
content:
'All we do is just sorta have an idea in our mind, and we just sorta let it happen. 🌈',
likes: 10
}
]
}
}
]
}
async function seed() {
await Promise.all(
getUsers().map((user) => {
return prisma.user.create({ data: user })
})
)
}
seed()

10
src/app.d.ts vendored Normal file
View file

@ -0,0 +1,10 @@
/// <reference types="@sveltejs/kit" />
// See https://kit.svelte.dev/docs/types#the-app-namespace
// for information about these interfaces
declare namespace App {
// interface Locals {}
// interface Platform {}
// interface Session {}
// interface Stuff {}
}

16
src/app.html Normal file
View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="" />
<link rel="icon" href="https://fav.farm/🐦️" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%svelte.head%
</head>
<body>
<div>%svelte.body%</div>
</body>
</html>

37
src/routes/__error.svelte Normal file
View file

@ -0,0 +1,37 @@
<script context="module" lang="ts">
import type { ErrorLoad } from '@sveltejs/kit'
export const load: ErrorLoad = ({ error, status}) => {
return {
props: {
title: `${status}: ${error.message}`
}
}
}
</script>
<script lang="ts">
export let title: string
</script>
<div class="error">
<h1>{title}</h1>
<img src="/error.webp" alt="Suprised cat">
</div>
<style>
.error {
height: 100vh;
display: grid;
gap: var(--spacing-32);
place-content: center;
place-items: center;
}
img {
width: 200px;
height: 200px;
border-radius: 50%;
object-fit: cover;
}
</style>

View file

@ -0,0 +1,5 @@
<script lang="ts">
import '$root/styles/global.css'
</script>
<slot />

1
src/routes/about.svelte Normal file
View file

@ -0,0 +1 @@
<h1>About</h1>

58
src/routes/index.svelte Normal file
View file

@ -0,0 +1,58 @@
<script lang="ts">
import { fly } from 'svelte/transition'
</script>
<svelte:head>
<title>Twittr</title>
</svelte:head>
<main class="container"
in:fly={{ x: -100, duration: 250, delay: 300 }}
out:fly={{ x: -100, duration: 250 }}>
<section class="hero">
<h1 class="title">Twittr 🐦️</h1>
<p class="text">Share your hot take with everyone.</p>
</section>
<section class="login">
<a class="btn" href="/home">🔥 Share Your Hot Take</a>
</section>
</main>
<style>
.container {
height: 100vh;
display: grid;
}
.hero,
.login {
display: grid;
place-content: center;
}
.hero {
background-color: var(--color-brand);
text-align: center;
}
.title {
font-size: var(--font-80);
z-index: 2;
}
.text {
padding: var(--spacing-16);
transform: rotate(2deg) translateY(-40%);
background: var(--color-bg-primary);
font-weight: bold;
font-size: var(--font-24);
z-index: 1;
}
@media (min-width: 1024px) {
.container {
grid-template-columns: repeat(2, 1fr);
}
}
</style>

131
src/styles/global.css Normal file
View file

@ -0,0 +1,131 @@
/* Setup */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap');
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--font-serif: 'Inter', sans-serif;
--font-16: 1.6rem;
--font-18: 1.8rem;
--font-24: 2.4rem;
--font-32: 3.2rem;
--font-80: 8rem;
--spacing-4: 0.4rem;
--spacing-8: 0.5rem;
--spacing-16: 1.6rem;
--spacing-20: 2rem;
--spacing-24: 2.4rem;
--spacing-32: 3.2rem;
--color-brand: hsl(204 88% 53%);
--color-text-primary: hsl(0 0% 98%);
--color-text-muted: hsl(210 34% 80%);
--color-bg-primary: hsl(210 34% 13%);
--color-bg-secondary: hsl(209, 35%, 15%);
--color-btn-primary-active: var(--color-brand);
--color-btn-primary-active-hover: hsl(204 88% 60%);
--color-btn-primary-inactive: hsl(205 70% 33%);
--color-btn-secondary: hsl(192 19% 95%);
--color-border-primary: hsl(0, 0%, 34%);
--color-link-hover: hsl(209 22% 19%);
--color-placeholder: hsl(210 34% 80%);
--radius-base: 2.4rem;
}
::-webkit-scrollbar {
width: 4px;
height: 4px;
}
::-webkit-scrollbar-track {
background-color: transparent;
}
::-webkit-scrollbar-thumb {
background-color: var(--color-brand);
border-radius: var(--radius-base);
}
html {
font-size: 62.5%;
}
html,
body {
height: 100%;
}
body {
font-family: var(--font-serif);
font-size: var(--font-18);
color: var(--color-text-primary);
background-color: var(--color-bg-primary);
}
a {
text-decoration: none;
color: var(--color-text-primary);
}
label {
display: block;
margin: var(--spacing-8) 0;
font-size: var(--font-24);
color: var(--color-text-muted);
}
input {
padding: var(--spacing-16);
font-size: var(--font-24);
border-radius: var(--radius-base);
border: none;
}
.btn {
padding: var(--spacing-16) var(--spacing-32);
font-size: var(--font-18);
font-weight: bold;
color: var(--color-text-primary);
background-color: var(--color-btn-primary-active);
border-radius: var(--radius-base);
border: none;
cursor: pointer;
}
.btn:hover {
background-color: var(--color-btn-primary-active-hover);
}
.btn:disabled {
color: var(--color-text-muted);
background-color: var(--color-btn-primary-inactive);
cursor: not-allowed;
}
ul,
ol {
list-style: none;
}
/* Utils */
.responsive {
resize: both;
overflow: scroll;
border: 1px solid hsl(0 0% 0%);
}
.placeholder {
padding: var(--spacing-20) 0;
background-color: var(--color-placeholder);
border-radius: var(--radius-base);
}

BIN
static/dancing.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 KiB

BIN
static/error.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

23
svelte.config.js Normal file
View file

@ -0,0 +1,23 @@
import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
import path from 'path';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
adapter: adapter(),
vite: {
resolve: {
alias: {
$root: path.resolve('./src')
}
}
}
}
};
export default config;

11
tsconfig.json Normal file
View file

@ -0,0 +1,11 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"$root/*": [
"./src/*"
]
}
}
}