-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61dbaa9
commit f0f4f14
Showing
11 changed files
with
132 additions
and
38 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,14 +1,78 @@ | ||
import { useLiveQuery } from "dexie-react-hooks"; | ||
import { sparkService } from "../../scripts/db/SparkService"; | ||
import { format } from "date-fns"; | ||
import type Spark from "../../interfaces/Spark"; | ||
|
||
export const SparkList = () => { | ||
const sparks = useLiveQuery(() => sparkService.listSparks()); | ||
|
||
const grouped = sparks?.reduce< | ||
{ | ||
key: string; | ||
prefixTags: string[]; | ||
sparks: Spark[]; | ||
}[] | ||
>((tmpGrouped, spark) => { | ||
const prevKey = | ||
tmpGrouped.length > 0 | ||
? tmpGrouped[tmpGrouped.length - 1].key | ||
: `${Math.random()}`; | ||
const nextKey = | ||
spark.contextTags.length > 0 | ||
? spark.contextTags.join("/") | ||
: `${Math.random()}`; | ||
if (prevKey === "" || prevKey !== nextKey) { | ||
tmpGrouped.push({ | ||
key: nextKey, | ||
prefixTags: spark.contextTags, | ||
sparks: [spark], | ||
}); | ||
return tmpGrouped; | ||
} | ||
|
||
tmpGrouped[tmpGrouped.length - 1].sparks.push(spark); | ||
return tmpGrouped; | ||
}, []); | ||
|
||
return ( | ||
<ul> | ||
{sparks?.map((spark) => ( | ||
<li key={spark.id}>{spark.plainText}</li> | ||
<div className="flex flex-col gap-16 py-10 bg-white h-full overflow-y-auto px-8"> | ||
{grouped?.map((group) => ( | ||
<section | ||
key={group.key} | ||
className="grid grid-cols-[25%_1fr] gap-8" | ||
> | ||
<div className="py-2 border-e border-slate-300 pe-4"> | ||
<div className="sticky top-1 flex flex-col gap-1"> | ||
{group.prefixTags.map((tag) => ( | ||
<span | ||
key={tag} | ||
className="font-bold text-md text-neutral-400" | ||
> | ||
{tag} | ||
</span> | ||
))} | ||
</div> | ||
</div> | ||
<div className="flex flex-col gap-10 py-2"> | ||
{group.sparks?.map((spark) => ( | ||
<article | ||
key={spark.id} | ||
className="flex flex-col gap-1" | ||
> | ||
<p className="text-neutral-900"> | ||
{spark.plainText} | ||
</p> | ||
<span className="text-neutral-500 font-thin text-xs ps-2"> | ||
{format( | ||
new Date(spark.creationDate), | ||
"dd.MM.yyyy", | ||
)} | ||
</span> | ||
</article> | ||
))} | ||
</div> | ||
</section> | ||
))} | ||
</ul> | ||
</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
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
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 |
---|---|---|
|
@@ -12,4 +12,5 @@ export default { | |
require("@tailwindcss/forms"), | ||
require("preline/plugin"), | ||
], | ||
darkMode: "selector", | ||
}; |