-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First steps to a todoist integration * Enable adding todos * Complete the todoist integration
- Loading branch information
Showing
16 changed files
with
564 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use flake |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ node_modules | |
!.env.example | ||
vite.config.js.timestamp-* | ||
vite.config.ts.timestamp-* | ||
.direnv/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; | ||
}; | ||
|
||
outputs = {self, nixpkgs}: let | ||
supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; | ||
forEachSupportedSystem = f: | ||
nixpkgs.lib.genAttrs supportedSystems (system: | ||
f { | ||
pkgs = import nixpkgs { | ||
inherit system; | ||
}; | ||
}); | ||
in { | ||
devShells = forEachSupportedSystem ({pkgs}: { | ||
default = pkgs.mkShell { | ||
packages = with pkgs; [ | ||
nodejs | ||
pnpm | ||
nodePackages.typescript-language-server | ||
prettierd | ||
]; | ||
shellHook = '' | ||
if [ ! -d node_modules ]; then | ||
echo "Use pnpm to install dependencies" | ||
fi | ||
''; | ||
}; | ||
}); | ||
}; | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<script context="module" lang="ts"> | ||
const todoitToken = svocal('settings.todo.todoist.code'); | ||
type Color = keyof typeof TODOIST_COLORS; | ||
async function createProject(name: string, color: Color) { | ||
const res = await fetch('https://api.todoist.com/rest/v2/projects', { | ||
method: Method.POST, | ||
headers: { Authorization: `Bearer ${get(todoitToken)}`, 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
name: name.trim() || 'Dlool', | ||
color, | ||
is_favourite: true, | ||
view_style: 'board' | ||
}) | ||
}).then((r) => r.json()); | ||
const scheme = z.object({ | ||
id: z.string(), | ||
name: z.string(), | ||
comment_count: z.number(), | ||
color: z.union([ | ||
z.literal('berry_red'), | ||
z.literal('red'), | ||
z.literal('orange'), | ||
z.literal('yellow'), | ||
z.literal('olive_green'), | ||
z.literal('lime_green'), | ||
z.literal('green'), | ||
z.literal('mint_green'), | ||
z.literal('teal'), | ||
z.literal('sky_blue'), | ||
z.literal('light_blue'), | ||
z.literal('blue'), | ||
z.literal('grape'), | ||
z.literal('violet'), | ||
z.literal('lavender'), | ||
z.literal('magenta'), | ||
z.literal('salmon'), | ||
z.literal('charcoal'), | ||
z.literal('grey'), | ||
z.literal('taupe') | ||
]), | ||
is_shared: z.boolean(), | ||
order: z.number(), | ||
is_favorite: z.boolean(), | ||
is_inbox_project: z.boolean(), | ||
is_team_inbox: z.boolean(), | ||
view_style: z.union([z.literal('list'), z.literal('board')]), | ||
url: z.string().url(), | ||
parent_id: z.nullable(z.unknown()) | ||
}); | ||
return scheme.parse(res); | ||
} | ||
</script> | ||
|
||
<script lang="ts"> | ||
import PrimaryButton from '$lib/components/buttons/PrimaryButton.svelte'; | ||
import TextInput from '$lib/components/input/Text.svelte'; | ||
import { sendDefaultErrorToast, sendToast } from '$lib/components/layout/toasts'; | ||
import Info from '$lib/components/utils/Info.svelte'; | ||
import { TODOIST_COLORS } from '$lib/constants/todoistColors'; | ||
import { i } from '$lib/i18n/store'; | ||
import { Method } from '$lib/utils/api'; | ||
import { objectEntries } from '$lib/utils/objects/entries'; | ||
import { svocal } from '$lib/utils/store/svocal'; | ||
import { createEventDispatcher } from 'svelte'; | ||
import { get, readable } from 'svelte/store'; | ||
import { z } from 'zod'; | ||
let selectedColor: Color = 'green'; | ||
let disabled = false; | ||
let name = 'Dlool'; | ||
const dispatch = createEventDispatcher<{ finish: string }>(); | ||
</script> | ||
|
||
<div class="flex max-w-[26rem] flex-col gap-4"> | ||
<Info> | ||
Dlool erstellt ein neues Todoist projekt, die Erinerrungen in diesem Projekt werden automatisch | ||
aktualisiert. Bitte ändere die Beschreibung deswegen nicht | ||
</Info> | ||
|
||
<h3>Neues Projekt</h3> | ||
<TextInput placeholder={readable('hallo')} bind:value={name} /> | ||
|
||
<h4>Farbe</h4> | ||
<div class="flex flex-wrap gap-1"> | ||
{#each objectEntries(TODOIST_COLORS) as [key, hex] (key)} | ||
<button | ||
on:click={() => { | ||
selectedColor = key; | ||
}} | ||
class="h-7 w-7 rounded-full border-solid border-black bg-[--bg] touch:h-10 touch:w-10" | ||
class:border-2={selectedColor === key} | ||
style:--bg={hex} | ||
/> | ||
{/each} | ||
</div> | ||
|
||
<PrimaryButton | ||
on:click={async () => { | ||
disabled = true; | ||
try { | ||
const { id } = await createProject(name, selectedColor); | ||
sendToast({ | ||
type: 'success', | ||
content: i('todoist.listCreated'), | ||
timeout: 5_000 | ||
}); | ||
dispatch('finish', id); | ||
} catch { | ||
disabled = false; | ||
sendDefaultErrorToast(); | ||
} | ||
}} | ||
{disabled} | ||
> | ||
Erstellen! | ||
</PrimaryButton> | ||
</div> |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const TODOIST_COLORS = { | ||
berry_red: '#b8256f', | ||
red: '#db4035', | ||
orange: '#ff9933', | ||
yellow: '#fad000', | ||
olive_green: '#afb83b', | ||
lime_green: '#7ecc49', | ||
green: '#299438', | ||
mint_green: '#6accbc', | ||
teal: '#158fad', | ||
sky_blue: '#14aaf5', | ||
light_blue: '#96c3eb', | ||
blue: '#4073ff', | ||
grape: '#884dff', | ||
violet: '#af38eb', | ||
lavender: '#eb96eb', | ||
magenta: '#e05194', | ||
salmon: '#ff8d85', | ||
charcoal: '#808080', | ||
grey: '#b8b8b8', | ||
taupe: '#ccac93' | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Method } from '$lib/utils/api'; | ||
import { svocal } from '$lib/utils/store/svocal'; | ||
import { internalSubjectRepresentation } from '$lib/utils/subjects/internal'; | ||
import { get } from 'svelte/store'; | ||
import { z } from 'zod'; | ||
|
||
const todoistToken = svocal('settings.todo.todoist.code'); | ||
const todoistProjectId = svocal('settings.todo.todoist.listId'); | ||
const todoistSections = svocal('settings.todo.todoist.projectIds'); | ||
|
||
const scheme = z.object({ id: z.string() }); | ||
|
||
export async function createSection(name: string) { | ||
const subject = internalSubjectRepresentation(name); | ||
|
||
if (get(todoistSections)[subject]) { | ||
return { id: get(todoistSections)[subject] }; | ||
} | ||
|
||
const res = await fetch('https://api.todoist.com/rest/v2/sections', { | ||
method: Method.POST, | ||
headers: { Authorization: `Bearer ${get(todoistToken)}`, 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ name, project_id: get(todoistProjectId) }) | ||
}).then((r) => r.json()); | ||
const parsed = scheme.parse(res); | ||
|
||
todoistSections.update((prev) => { | ||
prev[subject] = parsed.id; | ||
return prev; | ||
}); | ||
|
||
return parsed; | ||
} |
Oops, something went wrong.