-
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
06d5c01
commit 6ed0e0b
Showing
8 changed files
with
255 additions
and
142 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
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
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,25 @@ | ||
// import { Component, Resource } from "solid-js"; | ||
// import typia from "typia"; | ||
// | ||
// import { Database } from "sql.js"; | ||
// import "./App.css"; | ||
// | ||
// import { SegmentData } from "./Segment"; | ||
// | ||
// export interface DataSourceData { | ||
// id: string; | ||
// name: string; | ||
// url: string; | ||
// segments: SegmentData[]; | ||
// } | ||
// | ||
// | ||
// export const DataSource: Component<{ | ||
// data: DataSourceData; | ||
// selectedSegmentId: number; | ||
// }> = (props) => { | ||
// const { data, selectedSegmentId } = props; | ||
// | ||
// | ||
// | ||
// }; |
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,74 @@ | ||
import { For, Component, Resource } from "solid-js"; | ||
import { Word, WordData, fetchWords } from "./Word"; | ||
import { placeholders, queryToArray, queryToMaps } from "../sql"; | ||
import { Database } from "sql.js"; | ||
import { z } from "zod"; | ||
|
||
export const SegmentData = z.object({ | ||
id: z.number(), | ||
start: z.number(), | ||
end: z.number(), | ||
sourceName: z.string(), | ||
words: z.array(WordData), | ||
}); | ||
export type SegmentData = z.infer<typeof SegmentData>; | ||
|
||
export function fetchSegments( | ||
db: Resource<Database>, | ||
segmentIds: number[], | ||
): SegmentData[] { | ||
const connection = db(); | ||
if (!connection) { | ||
return []; | ||
} | ||
const segments = new Map( | ||
queryToMaps( | ||
db, | ||
` | ||
SELECT DISTINCT s.id, s.start_ms as start, s.end_ms as end, d.name as source_name | ||
FROM Segments as s | ||
JOIN DataSources AS d ON data_source_id = d.id | ||
WHERE s.id IN (${placeholders(segmentIds.length)}) | ||
ORDER BY source_name, start; | ||
`, | ||
...segmentIds, | ||
).map((s) => { | ||
const segment = SegmentData.parse({ | ||
id: s.get("id"), | ||
start: s.get("start"), | ||
end: s.get("end"), | ||
sourceName: s.get("source_name"), | ||
words: [], | ||
}); | ||
return [segment.id, segment]; | ||
}), | ||
); | ||
const wordIds = z.array(z.number()).parse( | ||
queryToArray( | ||
db, | ||
` | ||
SELECT id | ||
FROM Words | ||
WHERE segment_id IN (${placeholders(segmentIds.length)}); | ||
`, | ||
...segmentIds, | ||
), | ||
); | ||
for (const w of fetchWords(db, wordIds)) { | ||
const segment = segments.get(w.segmentId); | ||
if (segment) { | ||
segment.words.push(w); | ||
} else { | ||
console.error(`Cannot find segment with id: ${w.segmentId}`); | ||
} | ||
} | ||
return Array.from(segments.values()); | ||
} | ||
|
||
export const Segment: Component<{ data: SegmentData }> = (props) => { | ||
return ( | ||
<div class="segment card"> | ||
<For each={props.data.words}>{(t) => <Word data={t} />}</For> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.