Skip to content

Commit

Permalink
Switch to use start and end times in sentence_translation files
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Feb 27, 2024
1 parent 877d772 commit 17de32f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 34 deletions.
3 changes: 1 addition & 2 deletions app/src/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ export function maxCharsAllowed(language: string, start: number, end: number): n

/** get max length for entry translation text */
export function translationMax(
{ startingTranslation, startingOriginal, timeRange }: Entry,
{ startingTranslation, startingOriginal, start, end }: Entry,
language: string,
) {
const [start = 0, end = 0] = timeRange || [];
/** for entries with time range, i.e. captions */
if (start && end) return maxCharsAllowed(language, start, end);
/** for entries without a time range, i.e. title and description */ else
Expand Down
31 changes: 18 additions & 13 deletions app/src/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,35 @@ export type _Timings = [string, number, number][];
export type _Entry = {
input: string;
translatedText: string;
model?: string;
from_community_srt?: string;
n_reviews?: number;
start?: number;
end?: number;
n_reviews: number;
start: number;
end: number;
};

/** translation entry (title/description/entry) */
export type Entry = {
/** number of reviews (upvotes/edits) */
reviews: number;
/** upvoted state */
upvoted: boolean;
/** starting translation state */
startingTranslation: string;
/** translation edit state */
currentTranslation: string;
/** starting original english state */
startingOriginal: string;
/** original english edit state */
currentOriginal: string;
/** timestamp range */
timeRange?: [number, number];
/** starting translation state */
startingTranslation: string;
/** translation edit state */
currentTranslation: string;
/** translation model */
model?: string;
/** old built-in youtube community translation */
legacyTranslation?: string;
/** number of reviews (upvotes/edits) */
reviews: number;
/** upvoted state */
upvoted: boolean;
/** start time */
start: number;
/** end time */
end: number;
};

/** language/topic/lesson completion format */
Expand Down
11 changes: 0 additions & 11 deletions app/src/pages/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,6 @@ export const loader: LoaderFunction = async ({ params }) => {
if (data) setAtom(captions, data.map(convert));
}

/** load caption timings */
{
const url = `${base}/${path}/english/sentence_timings.json`;
const data = await request<_Timings>(url);
if (data)
data.forEach(([, start, end], index) => {
if (getAtom(captions)[index])
getAtom(captions)[index]!.timeRange = [start, end];
});
}

/** alert about locked status */
if (getAtom(locked))
window.setTimeout(() => {
Expand Down
15 changes: 7 additions & 8 deletions app/src/pages/edit/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,16 @@ function Row({ index, entries }: Props) {

/** extract entry props */
const {
reviews,
upvoted,
startingTranslation,
currentTranslation,
startingOriginal,
currentOriginal,
timeRange,
startingTranslation,
currentTranslation,
legacyTranslation,
reviews,
upvoted,
start,
end,
} = entry;
const [start = 0, end = 0] = timeRange || [];

const ref = useRef<HTMLDivElement>(null);

/** url params */
Expand Down Expand Up @@ -109,7 +108,7 @@ function Row({ index, entries }: Props) {
<span>{edited ? 1 : reviews + Number(upvoted)}</span>
</button>

{timeRange && (
{(start && end) && (
<button
className={classes.action}
onClick={() => {
Expand Down

0 comments on commit 17de32f

Please sign in to comment.