-
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.
Co-authored-by: ttizze <[email protected]>
- Loading branch information
Showing
16 changed files
with
356 additions
and
232 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
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 |
---|---|---|
|
@@ -31,7 +31,7 @@ jobs: | |
esac | ||
done | ||
BRANCH_NAME="${ASSIGNEE,,}/issue-${ISSUE_NUMBER}-${TYPE}" | ||
BRANCH_NAME="${ASSIGNEE,,}/${TYPE}-issue-${ISSUE_NUMBER}" | ||
git config user.name "GitHub Actions" | ||
git config user.email "[email protected]" | ||
|
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,28 @@ | ||
name: Link PR to Issue | ||
|
||
on: | ||
pull_request: | ||
types: [opened] | ||
|
||
jobs: | ||
link_pr_to_issue: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Extract issue number from branch name | ||
id: extract-issue | ||
run: | | ||
BRANCH_NAME="${{ github.head_ref }}" | ||
ISSUE_NUMBER=$(echo $BRANCH_NAME | grep -oP 'issue-\K\d+') | ||
echo "issue_number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT | ||
- name: Link PR to issue | ||
if: steps.extract-issue.outputs.issue_number | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
ISSUE_NUMBER: ${{ steps.extract-issue.outputs.issue_number }} | ||
run: | | ||
gh pr edit $PR_NUMBER --add-label "linked-to-issue" | ||
gh pr comment $PR_NUMBER --body "This PR is linked to issue #$ISSUE_NUMBER" | ||
gh issue edit $ISSUE_NUMBER --add-project "Project Board Name" | ||
gh issue comment $ISSUE_NUMBER --body "PR #$PR_NUMBER has been linked to this issue" |
71 changes: 71 additions & 0 deletions
71
web/app/routes/reader.$encodedUrl/components/AddAndVoteTranslations.tsx
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,71 @@ | ||
import { ChevronDown, ListTree, PlusCircle } from "lucide-react"; | ||
import { useMemo, useState } from "react"; | ||
import { Button } from "~/components/ui/button"; | ||
import type { TranslationWithVote } from "../types"; | ||
import { AddTranslationForm } from "./AddTranslationForm"; | ||
import { AlternativeTranslations } from "./AlternativeTranslations"; | ||
import { TranslationItem } from "./TranslationItem"; | ||
|
||
const INITIAL_DISPLAY_COUNT = 3; | ||
|
||
export function AddAndVoteTranslations({ | ||
bestTranslationWithVote, | ||
alternativeTranslationsWithVotes, | ||
userId, | ||
sourceTextId, | ||
}: { | ||
bestTranslationWithVote: TranslationWithVote; | ||
alternativeTranslationsWithVotes: TranslationWithVote[]; | ||
userId: number | null; | ||
sourceTextId: number; | ||
}) { | ||
const [showAll, setShowAll] = useState(false); | ||
|
||
const displayedTranslations = useMemo(() => { | ||
return showAll | ||
? alternativeTranslationsWithVotes | ||
: alternativeTranslationsWithVotes.slice(0, INITIAL_DISPLAY_COUNT); | ||
}, [alternativeTranslationsWithVotes, showAll]); | ||
|
||
const hasMoreTranslations = | ||
alternativeTranslationsWithVotes.length > INITIAL_DISPLAY_COUNT; | ||
|
||
return ( | ||
<div className="p-4 "> | ||
<TranslationItem | ||
translation={bestTranslationWithVote} | ||
userId={userId} | ||
showAuthor | ||
/> | ||
<div className="mt-4"> | ||
<h4 className="text-sm flex items-center justify-end gap-2"> | ||
<ListTree size={16} /> | ||
Alternative Translations | ||
</h4> | ||
<AlternativeTranslations | ||
translationsWithVotes={displayedTranslations} | ||
userId={userId} | ||
/> | ||
{hasMoreTranslations && !showAll && ( | ||
<Button | ||
variant="link" | ||
className="mt-2 w-full text-sm" | ||
onClick={() => setShowAll(true)} | ||
> | ||
<ChevronDown size={16} className="mr-1" /> | ||
Show more | ||
</Button> | ||
)} | ||
</div> | ||
{userId && ( | ||
<div className="mt-4"> | ||
<h4 className="text-sm flex items-center justify-end gap-2"> | ||
<PlusCircle size={16} /> | ||
Add Your Translation | ||
</h4> | ||
<AddTranslationForm sourceTextId={sourceTextId} /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
48 changes: 14 additions & 34 deletions
48
web/app/routes/reader.$encodedUrl/components/AddTranslationForm.tsx
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
73 changes: 73 additions & 0 deletions
73
web/app/routes/reader.$encodedUrl/components/ContentWithTranslations.tsx
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,73 @@ | ||
import DOMPurify from "dompurify"; | ||
import parse from "html-react-parser"; | ||
import { memo, useMemo } from "react"; | ||
import type { SourceTextInfoWithTranslations } from "../types"; | ||
import { Translation } from "./Translation"; | ||
|
||
interface ContentWithTranslationsProps { | ||
content: string; | ||
sourceTextInfoWithTranslations: SourceTextInfoWithTranslations[]; | ||
targetLanguage: string; | ||
userId: number | null; | ||
} | ||
|
||
export const ContentWithTranslations = memo(function ContentWithTranslations({ | ||
content, | ||
sourceTextInfoWithTranslations, | ||
targetLanguage, | ||
userId, | ||
}: ContentWithTranslationsProps) { | ||
const parsedContent = useMemo(() => { | ||
if (typeof window === "undefined") { | ||
return null; | ||
} | ||
|
||
const sanitizedContent = DOMPurify.sanitize(content); | ||
const doc = new DOMParser().parseFromString(sanitizedContent, "text/html"); | ||
const translationMap = new Map( | ||
sourceTextInfoWithTranslations.map((info) => [ | ||
info.number.toString(), | ||
info, | ||
]), | ||
); | ||
|
||
for (const [number] of translationMap) { | ||
const element = doc.querySelector(`[data-number="${number}"]`); | ||
if (element instanceof HTMLElement) { | ||
const translationElement = doc.createElement("div"); | ||
translationElement.setAttribute("data-translation", number); | ||
element.appendChild(translationElement); | ||
} | ||
} | ||
|
||
return parse(doc.body.innerHTML, { | ||
replace: (domNode) => { | ||
if (domNode.type === "tag" && domNode.attribs["data-translation"]) { | ||
const number = domNode.attribs["data-translation"]; | ||
const translationGroup = translationMap.get(number); | ||
if ( | ||
translationGroup && | ||
translationGroup.translationsWithVotes.length > 0 | ||
) { | ||
return ( | ||
<Translation | ||
key={`translation-group-${number}`} | ||
translationsWithVotes={translationGroup.translationsWithVotes} | ||
targetLanguage={targetLanguage} | ||
userId={userId} | ||
sourceTextId={translationGroup.sourceTextId} | ||
/> | ||
); | ||
} | ||
} | ||
return domNode; | ||
}, | ||
}); | ||
}, [content, sourceTextInfoWithTranslations, targetLanguage, userId]); | ||
|
||
if (typeof window === "undefined") { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
return <>{parsedContent}</>; | ||
}); |
65 changes: 0 additions & 65 deletions
65
web/app/routes/reader.$encodedUrl/components/TranslatedContent.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.