Skip to content

Commit

Permalink
Merge branch 'alpha' into heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
xerosanyam committed Aug 12, 2024
2 parents 7b72f70 + 259f14b commit 064ee2e
Show file tree
Hide file tree
Showing 30 changed files with 905 additions and 222 deletions.
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"command": "bun run dev",
"name": "Run development server",
"request": "launch",
"type": "node-terminal"
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}"
}
]
}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
preload = "./happydom.ts"
4 changes: 4 additions & 0 deletions essays/setup/1. google-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
1. [Google oauth screen](https://console.cloud.google.com/apis/credentials/oauthclient/866296044896-9eb9a2762g9m1kcuqbevqppc4ukdbnbn.apps.googleusercontent.com?project=read-to-remember)

2. [update env variables](https://vercel.com/sanyam-jains-projects-1b330221/remfo/settings/domains)

3. update REDIRECT_URI

4. [check domains preview/production setting](https://vercel.com/sanyam-jains-projects-1b330221/remfo/settings/domains)
17 changes: 17 additions & 0 deletions essays/things-you-will-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Frontend

- svelte

## Backend

- designing RESTful APIs
- working with databases

## System Design

## DSA

## Programming

- best practices
- testing & code-quality
3 changes: 3 additions & 0 deletions happydom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { GlobalRegistrator } from "@happy-dom/global-registrator";

GlobalRegistrator.register();
84 changes: 49 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,78 @@
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"build": "bun run test && vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test": "vitest",
"test": "vitest run",
"test:ui": "vitest --ui",
"test:watch": "vitest",
"lint": "prettier --check . && eslint .",
"format": "prettier --write .",
"generate": "npx drizzle-kit generate",
"migrate": "npx drizzle-kit migrate"
},
"devDependencies": {
"@iconify/json": "^2.2.214",
"@happy-dom/global-registrator": "^14.12.3",
"@iconify/json": "^2.2.230",
"@iconify/types": "^2.0.0",
"@libsql/client": "0.6.0",
"@libsql/client": "0.7.0",
"@lucia-auth/adapter-postgresql": "3.1.2",
"@lucia-auth/adapter-sqlite": "3.0.1",
"@sveltejs/adapter-auto": "3.2.1",
"@sveltejs/adapter-vercel": "5.3.0",
"@sveltejs/enhanced-img": "^0.2.1",
"@sveltejs/kit": "2.5.10",
"@sveltejs/vite-plugin-svelte": "3.1.0",
"@lucia-auth/adapter-sqlite": "3.0.2",
"@sveltejs/adapter-auto": "3.2.2",
"@sveltejs/adapter-vercel": "5.4.1",
"@sveltejs/enhanced-img": "^0.3.0",
"@sveltejs/kit": "2.5.18",
"@sveltejs/vite-plugin-svelte": "3.1.1",
"@tailwindcss/typography": "0.5.13",
"@types/eslint": "8.56.10",
"@typescript-eslint/eslint-plugin": "7.10.0",
"@typescript-eslint/parser": "7.10.0",
"@testing-library/jest-dom": "^6.4.7",
"@testing-library/svelte": "^5.2.0",
"@types/eslint": "9.6.0",
"@typescript-eslint/eslint-plugin": "7.17.0",
"@typescript-eslint/parser": "7.17.0",
"@vercel/analytics": "^1.3.1",
"@vite-pwa/sveltekit": "^0.5.0",
"arctic": "1.9.0",
"@vite-pwa/sveltekit": "^0.6.0",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/ui": "^2.0.4",
"@zerodevx/svelte-toast": "^0.9.5",
"arctic": "1.9.2",
"autoprefixer": "10.4.19",
"cal-heatmap": "^4.2.4",
"cypress": "^13.12.0",
"cypress": "^13.13.1",
"date-fns": "3.6.0",
"dotenv": "16.4.5",
"drizzle-kit": "0.21.4",
"drizzle-orm": "0.30.10",
"eslint": "8.57.0",
"drizzle-kit": "0.23.0",
"drizzle-orm": "0.32.0",
"eslint": "9.7.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-svelte": "2.39.0",
"eslint-plugin-svelte": "2.43.0",
"lucia": "3.2.0",
"openai": "4.47.1",
"postcss": "8.4.38",
"msw": "^2.3.5",
"openai": "4.53.0",
"postcss": "8.4.39",
"postgres": "3.4.4",
"posthog-js": "^1.141.4",
"prettier": "3.2.5",
"prettier-plugin-svelte": "3.2.3",
"prettier-plugin-tailwindcss": "0.5.14",
"svelte": "5.0.0-next.142",
"svelte-check": "3.7.1",
"sveltekit-device-detector": "^1.1.2",
"sveltekit-superforms": "2.14.0",
"tailwindcss": "3.4.3",
"tslib": "2.6.2",
"typescript": "5.4.5",
"posthog-js": "^1.148.2",
"prettier": "3.3.3",
"prettier-plugin-svelte": "3.2.6",
"prettier-plugin-tailwindcss": "0.6.5",
"svelte": "5.0.0-next.195",
"svelte-check": "3.8.4",
"sveltekit-device-detector": "^1.1.3",
"sveltekit-superforms": "2.16.1",
"tailwindcss": "3.4.6",
"tslib": "2.6.3",
"typescript": "5.5.4",
"unplugin-icons": "^0.19.0",
"vite": "5.2.11",
"vite": "5.3.4",
"vite-plugin-pwa": "^0.20.0",
"vitest": "1.6.0",
"zod": "3.23.8"
},
"type": "module"
"type": "module",
"msw": {
"workerDirectory": [
"static"
]
}
}
56 changes: 56 additions & 0 deletions src/lib/components/Cards/Card.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script lang="ts">
import type { CardRevisePage } from '$lib/types/Card';
import { formatDistanceToNow } from 'date-fns';
import Trash from '~icons/arcticons/trashcan';
import ReviewOptions from './ReviewOptions.svelte';
import { enhance } from '$app/forms';
export let card: CardRevisePage;
export let customEnhance;
export let modifyingCardId: string;
</script>

<div class="group relative rounded-md border border-gray-100 bg-white sm:h-96">
<div class={`flex h-full w-full flex-col ${modifyingCardId === card.id ? 'blur-sm' : ''}`}>
<div
class="flex h-fit min-h-16 max-h-48 w-full justify-center overflow-y-auto rounded-md border-input ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
id="question"
>
<div class="w-full whitespace-break-spaces p-6">
{card.front}
</div>
</div>

<div class="relative flex grow min-h-48 border-t border-dashed">
<form
class="absolute -top-5 right-0 z-10 bg-white"
method="post"
action="?/delete"
use:enhance={customEnhance}
>
<input type="hidden" hidden name="cardId" value={card.id} />
<button
class="flex items-center space-x-1 rounded-md border px-4 py-2 hover:bg-accent hover:text-accent-foreground hover:outline disabled:pointer-events-none disabled:opacity-50"
disabled={modifyingCardId === card.id}
type="submit"
title="move to trash"
data-testid="trash"
>
<Trash style="stroke-width:2px;" /><span></span>
</button>
</form>
<div
class="h-full w-full items-center overflow-y-auto whitespace-break-spaces p-6 ring-offset-background blur-md placeholder:text-muted-foreground hover:filter-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
id="answer"
>
{card.back}
</div>
</div>
<div class="w-full">
<ReviewOptions cardId={card.id} {customEnhance} />
</div>
</div>
</div>
<div class="p-2 text-right text-sm text-gray-200" title={String(card.createdAt)}>
added {formatDistanceToNow(card.createdAt)} ago
</div>
26 changes: 26 additions & 0 deletions src/lib/components/Cards/CardGroup.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script lang="ts">
import type { CardRevisePage } from '$lib/types/Card';
import { humanReadableDate } from '$lib/common.util';
import Card from './Card.svelte';
export let date: string;
export let cards: CardRevisePage[];
export let customEnhance;
export let modifyingCardId: string;
export let firstCardId: string;
</script>

<div class="relative">
<div
class="mb-2 flex h-10 w-16 items-center justify-center rounded-full border border-gray-100 text-center text-gray-400"
title={date}
>
{humanReadableDate(cards[0].nextPractice)}
</div>
<div class="absolute left-8 top-10 -z-10 h-full border-r border-gray-100"></div>
{#each cards as card (card.id)}
<div class="{`mb-16 ${card.id === firstCardId ? 'first:min-h-screen' : ''}`}}">
<Card {card} {customEnhance} {modifyingCardId}></Card>
</div>
{/each}
</div>
71 changes: 71 additions & 0 deletions src/lib/components/Cards/CardReview.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<script lang="ts">
import type { CardRevisePage } from '$lib/types/Card';
import type { ActionResult } from '@sveltejs/kit';
import { format } from 'date-fns';
import CardGroup from './CardGroup.svelte';
import ReviewProgress from './ReviewProgress.svelte';
import { toast } from '@zerodevx/svelte-toast';
export let cards: CardRevisePage[];
let groupedCards: { [key: string]: CardRevisePage[] } = {};
let dates: string[] = [];
let revisedCards: string[] = [];
let remainingCards: CardRevisePage[] = [];
let firstCardId = '';
$: {
remainingCards = cards.filter((card) => !revisedCards.includes(card.id));
groupedCards = groupCards(remainingCards);
dates = Object.keys(groupedCards).sort((a, b) => new Date(a).getTime() - new Date(b).getTime());
firstCardId = groupCards(remainingCards)[dates[0]]?.[0]?.id;
}
let modifyingCardId = '';
const customEnhance = ({ formData }: { formData: FormData }) => {
const id = formData.get('cardId') as string;
revisedCards = [...revisedCards, id];
modifyingCardId = id;
return ({ result }: { result: ActionResult }) => {
modifyingCardId = '';
if (result.type === 'error' || result.type === 'failure') {
toast.push('Failed to perform that action', {
theme: {
'--toastColor': 'white',
'--toastBackground': 'rgba(220,53,69,0.9)',
'--toastBarBackground': '#C53030'
}
});
}
};
};
function groupCards(cards: CardRevisePage[]): { [key: string]: CardRevisePage[] } {
return cards.reduce((groups: { [key: string]: CardRevisePage[] }, card) => {
const date = format(card.nextPractice, 'P');
if (!groups[date]) {
groups[date] = [];
}
groups[date].push(card);
return groups;
}, {});
}
</script>

<div class="relative mx-auto mt-10 max-w-lg space-y-4 rounded-lg">
<ReviewProgress {remainingCards} {revisedCards} {cards} />

<div class="mx-4 mt-10">
{#if cards.length > 0}
{#each dates as date (date)}
<CardGroup
{firstCardId}
{date}
cards={groupedCards[date]}
{customEnhance}
{modifyingCardId}
/>
{/each}
{/if}
</div>
</div>
30 changes: 30 additions & 0 deletions src/lib/components/Cards/ReviewOptions.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script lang="ts">
import { enhance } from '$app/forms';
export let cardId: string;
export let customEnhance;
const options = [
{ value: 'Easy', text: 'super easy' },
{ value: 'Good', text: 'easy' },
{ value: 'Hard', text: 'difficult' },
{ value: 'Challenging', text: 'super difficult' }
];
</script>

<form method="post" action="?/review" use:enhance={customEnhance}>
<input type="hidden" hidden name="cardId" value={cardId} />
<div
class="flex w-full flex-col border-t border-gray-100 sm:flex-row sm:rounded-bl-md sm:rounded-br-md"
>
{#each options as { value, text } (value)}
<button
class="w-full whitespace-nowrap border-b border-gray-100 bg-background px-4 py-4 text-center -outline-offset-2 ring-offset-background transition-colors last:rounded-b-sm hover:bg-accent hover:text-accent-foreground hover:outline focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 sm:border-b-0 sm:border-l sm:first:rounded-bl-sm sm:first:border-l-0 sm:last:rounded-bl-none sm:last:rounded-br-sm"
name="difficulty"
{value}
>
<span>{text}</span>
</button>
{/each}
</div>
</form>
22 changes: 22 additions & 0 deletions src/lib/components/Cards/ReviewProgress.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script lang="ts">
import type { CardRevisePage } from '$lib/types/Card';
export let cards: CardRevisePage[];
export let revisedCards: string[];
export let remainingCards: CardRevisePage[];
let reviseCards = 5;
</script>

{#if remainingCards.length === 0}
<div class="text-center">
You have revised all the cards. Go to <a href="/record" class="underline">Record</a> to create more
</div>
{:else if revisedCards.length > 0 && revisedCards.length % reviseCards === 0}
<div class="text-center text-lg text-gray-500">
Hurray. You revised {revisedCards.length} cards. Take a break or keep going.
</div>
{:else}
<div class="text-center text-lg text-gray-400">
cards reviewed: {revisedCards.length}/{cards.length}
</div>
{/if}
Loading

0 comments on commit 064ee2e

Please sign in to comment.