Initial commit
This commit is contained in:
commit
46c7eb35b3
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
9
.prettierrc
Normal file
9
.prettierrc
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"svelteStrictMode": true,
|
||||
"svelteSortOrder": "options-styles-scripts-markup",
|
||||
"svelteBracketNewLine": true,
|
||||
"svelteIndentScriptAndStyle": true,
|
||||
"svelteAllowShorthand": false
|
||||
}
|
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["svelte.svelte-vscode"]
|
||||
}
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 niku
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
47
README.md
Normal file
47
README.md
Normal file
@ -0,0 +1,47 @@
|
||||
# Svelte + TS + Vite
|
||||
|
||||
This template should help get you started developing with Svelte and TypeScript in Vite.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
|
||||
|
||||
## Need an official Svelte framework?
|
||||
|
||||
Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
|
||||
|
||||
## Technical considerations
|
||||
|
||||
**Why use this over SvelteKit?**
|
||||
|
||||
- It brings its own routing solution which might not be preferable for some users.
|
||||
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
|
||||
|
||||
This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
|
||||
|
||||
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
|
||||
|
||||
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
|
||||
|
||||
Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.
|
||||
|
||||
**Why include `.vscode/extensions.json`?**
|
||||
|
||||
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
|
||||
|
||||
**Why enable `allowJs` in the TS template?**
|
||||
|
||||
While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant.
|
||||
|
||||
**Why is HMR not preserving my local component state?**
|
||||
|
||||
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr).
|
||||
|
||||
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
|
||||
|
||||
```ts
|
||||
// store.ts
|
||||
// An extremely simple external store
|
||||
import { writable } from 'svelte/store'
|
||||
export default writable(0)
|
||||
```
|
5
codegen.yml
Normal file
5
codegen.yml
Normal file
@ -0,0 +1,5 @@
|
||||
generates:
|
||||
src/lib/types/anilist.ts:
|
||||
schema: https://graphql.anilist.co
|
||||
plugins:
|
||||
- typescript
|
13
index.html
Normal file
13
index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Svelte + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
35
package.json
Normal file
35
package.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "al-watch-compare",
|
||||
"description": "Compare your AniList progress with your friends.",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"check": "svelte-check --tsconfig ./tsconfig.json",
|
||||
"codegen": "graphql-codegen"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@graphql-codegen/cli": "2.16.4",
|
||||
"@graphql-codegen/client-preset": "^1.2.6",
|
||||
"@graphql-codegen/typescript": "2.8.7",
|
||||
"@sveltejs/vite-plugin-svelte": "^2.0.0",
|
||||
"@tsconfig/svelte": "^3.0.0",
|
||||
"autoprefixer": "^10.4.13",
|
||||
"postcss": "^8.4.21",
|
||||
"svelte": "^3.54.0",
|
||||
"svelte-check": "^2.10.0",
|
||||
"tailwindcss": "^3.2.4",
|
||||
"ts-node": "^10.9.1",
|
||||
"tslib": "^2.4.1",
|
||||
"typescript": "^4.9.4",
|
||||
"vite": "^4.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@open-draft/until": "^2.0.0",
|
||||
"dayjs": "^1.11.7",
|
||||
"graphql": "^16.6.0"
|
||||
}
|
||||
}
|
4231
pnpm-lock.yaml
generated
Normal file
4231
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
6
postcss.config.cjs
Normal file
6
postcss.config.cjs
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
99
src/App.svelte
Normal file
99
src/App.svelte
Normal file
@ -0,0 +1,99 @@
|
||||
<script lang="ts">
|
||||
import type { MediaListCollection, ProgressRow, RowId } from "./lib/types";
|
||||
import { term, items, filtered } from "./stores/table";
|
||||
import RowHeader from "./lib/components/table/RowHeader.svelte";
|
||||
import { AniList } from "./lib/services/anilist";
|
||||
import { formatProgress } from "./lib/utils/formatting";
|
||||
|
||||
let inputUser = "";
|
||||
let progressIndex = [];
|
||||
|
||||
function hotEncode(index, data) {
|
||||
return index.map((idx) => data[idx] ?? null);
|
||||
}
|
||||
|
||||
function processUser(userName: string, mediaList: MediaListCollection) {
|
||||
progressIndex.push(userName);
|
||||
|
||||
for (const list of mediaList.lists) {
|
||||
for (const listEntry of list.entries) {
|
||||
let rowId = listEntry.media.id;
|
||||
|
||||
let row: ProgressRow = $items.get(rowId) ?? {
|
||||
media: listEntry.media,
|
||||
progress: {},
|
||||
};
|
||||
|
||||
row.progress[userName] = listEntry.progress;
|
||||
|
||||
items.update((map) => map.set(rowId, row));
|
||||
}
|
||||
}
|
||||
|
||||
progressIndex = progressIndex;
|
||||
}
|
||||
|
||||
async function handleAddUser() {
|
||||
if (inputUser.length === 0) return;
|
||||
const { error, data } = await AniList.fetchMediaList(inputUser);
|
||||
|
||||
const resp = await data.json();
|
||||
processUser(inputUser, resp.data.MediaListCollection);
|
||||
|
||||
inputUser = "";
|
||||
}
|
||||
|
||||
let searchTerm = "";
|
||||
$: term.set(searchTerm.toLowerCase());
|
||||
|
||||
const styleClasses = {
|
||||
tableHeader: "text-sm font-medium text-gray-900 px-6 py-4 text-left",
|
||||
};
|
||||
</script>
|
||||
|
||||
<main class="w-screen min-h-screen bg-slate-50">
|
||||
<div class="container mx-auto">
|
||||
<table class="min-w-full">
|
||||
<thead>
|
||||
<th scope="col" class="{styleClasses.tableHeader} w-1/3">
|
||||
<input
|
||||
class="border rounded-sm px-3 py-2"
|
||||
type="text"
|
||||
placeholder="Filter media"
|
||||
bind:value="{searchTerm}"
|
||||
/>
|
||||
</th>
|
||||
{#each progressIndex as userName}
|
||||
<th scope="col" class="{styleClasses.tableHeader}">
|
||||
{userName}
|
||||
</th>
|
||||
{/each}
|
||||
<th scope="col" class="{styleClasses.tableHeader}">
|
||||
<input
|
||||
class="border rounded-sm px-3 py-2"
|
||||
type="text"
|
||||
placeholder="AniList user"
|
||||
bind:value="{inputUser}"
|
||||
/>
|
||||
<button class="py-2 px-3 bg-gray-100" on:click="{handleAddUser}">
|
||||
Add User
|
||||
</button>
|
||||
</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each Array.from($filtered.values()) as { media, progress }}
|
||||
<tr>
|
||||
<td class="px-6 py-3 text-sm font-medium text-gray-900">
|
||||
<RowHeader media="{media}" />
|
||||
</td>
|
||||
{#each hotEncode(progressIndex, progress) as entry}
|
||||
<td class="text-sm text-gray-900 font-light px-6 py-4">
|
||||
{formatProgress(entry, media.episodes)}
|
||||
</td>
|
||||
{/each}
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
25
src/lib/components/table/RowHeader.svelte
Normal file
25
src/lib/components/table/RowHeader.svelte
Normal file
@ -0,0 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { type Media } from "../../types";
|
||||
import { formatTimestamp } from "../../utils/formatting";
|
||||
|
||||
export let media: Media;
|
||||
</script>
|
||||
|
||||
<a href="{media.siteUrl}" target="_blank" rel="noreferrer">
|
||||
<div class="flex flex-row items-center space-x-2">
|
||||
<img src="{media.coverImage.medium}" alt="cover" class="h-20 rounded-sm" />
|
||||
<div>
|
||||
<p class="text-ellipsis">
|
||||
{media.title.english ?? media.title.romaji}
|
||||
</p>
|
||||
<p>Status: {media.status}</p>
|
||||
{#if media.nextAiringEpisode}
|
||||
<p>
|
||||
Ep. {media.nextAiringEpisode.episode} airs: {formatTimestamp(
|
||||
media.nextAiringEpisode.airingAt
|
||||
)}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
22
src/lib/services/anilist/index.ts
Normal file
22
src/lib/services/anilist/index.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { until } from "@open-draft/until";
|
||||
import { mediaListQuery } from "./queries";
|
||||
|
||||
export class AniList {
|
||||
static apiUrl = "https://graphql.anilist.co";
|
||||
|
||||
static buildOptions(query, variables) {
|
||||
return {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
},
|
||||
body: JSON.stringify({ query, variables }),
|
||||
};
|
||||
}
|
||||
|
||||
static async fetchMediaList(username: string) {
|
||||
const options = this.buildOptions(mediaListQuery, { username });
|
||||
return await until(() => fetch(this.apiUrl, options));
|
||||
}
|
||||
}
|
30
src/lib/services/anilist/queries.ts
Normal file
30
src/lib/services/anilist/queries.ts
Normal file
@ -0,0 +1,30 @@
|
||||
export const mediaListQuery = `
|
||||
query me($username: String) {
|
||||
MediaListCollection(userName: $username, type: ANIME, status:CURRENT) {
|
||||
lists {
|
||||
entries {
|
||||
progress
|
||||
media {
|
||||
id
|
||||
status(version:2)
|
||||
coverImage {
|
||||
medium
|
||||
color
|
||||
}
|
||||
genres
|
||||
siteUrl
|
||||
title {
|
||||
romaji
|
||||
english
|
||||
}
|
||||
nextAiringEpisode {
|
||||
airingAt
|
||||
episode
|
||||
}
|
||||
episodes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
4665
src/lib/types/anilist.ts
Normal file
4665
src/lib/types/anilist.ts
Normal file
File diff suppressed because it is too large
Load Diff
8
src/lib/types/index.ts
Normal file
8
src/lib/types/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import type { Media } from "./anilist";
|
||||
|
||||
export * from "./anilist";
|
||||
|
||||
export type RowId = number;
|
||||
export type ProgressEntry = Record<string, number>;
|
||||
export type ProgressRow = { media: Media; progress: ProgressEntry };
|
||||
export type ProgressTable = Map<RowId, ProgressRow>;
|
23
src/lib/utils/formatting.ts
Normal file
23
src/lib/utils/formatting.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
export function formatTimestamp(unix: number): string {
|
||||
return dayjs(unix * 1000)
|
||||
.local()
|
||||
.format("MM-DDTHH");
|
||||
}
|
||||
|
||||
export function formatProgress(
|
||||
current: number | null,
|
||||
total: number | null
|
||||
): string {
|
||||
if (Number.isInteger(current) === false) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let res = current.toString();
|
||||
if (Number.isInteger(total)) res += `/${total}`;
|
||||
return res;
|
||||
}
|
8
src/main.ts
Normal file
8
src/main.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import "./styles/index.css";
|
||||
import App from "./App.svelte";
|
||||
|
||||
const app = new App({
|
||||
target: document.getElementById("app"),
|
||||
});
|
||||
|
||||
export default app;
|
20
src/stores/table.ts
Normal file
20
src/stores/table.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { writable, derived } from "svelte/store";
|
||||
import type { ProgressRow, ProgressTable, RowId } from "../lib/types";
|
||||
|
||||
export const term = writable("");
|
||||
|
||||
export const items = writable<ProgressTable>(new Map());
|
||||
|
||||
function search([term, items]): ProgressTable {
|
||||
return new Map(
|
||||
[...items].filter(([_, value]: [RowId, ProgressRow]) => {
|
||||
let title = value.media.title;
|
||||
return (
|
||||
title.english?.toLowerCase().includes(term) ||
|
||||
title.romaji?.toLowerCase().includes(term)
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const filtered = derived([term, items], search);
|
3
src/styles/index.css
Normal file
3
src/styles/index.css
Normal file
@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
2
src/vite-env.d.ts
vendored
Normal file
2
src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/// <reference types="svelte" />
|
||||
/// <reference types="vite/client" />
|
7
svelte.config.js
Normal file
7
svelte.config.js
Normal file
@ -0,0 +1,7 @@
|
||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
||||
|
||||
export default {
|
||||
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
}
|
8
tailwind.config.cjs
Normal file
8
tailwind.config.cjs
Normal file
@ -0,0 +1,8 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ["./index.html", "./src/**/*.svelte"],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
20
tsconfig.json
Normal file
20
tsconfig.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"resolveJsonModule": true,
|
||||
/**
|
||||
* Typecheck JS in `.svelte` and `.js` files by default.
|
||||
* Disable checkJs if you'd like to use dynamic types in JS.
|
||||
* Note that setting allowJs false does not prevent the use
|
||||
* of JS in `.svelte` files.
|
||||
*/
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"isolatedModules": true
|
||||
},
|
||||
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
8
tsconfig.node.json
Normal file
8
tsconfig.node.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node"
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
7
vite.config.ts
Normal file
7
vite.config.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [svelte()],
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user