-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2408 from codecrafters-io/code-mirror/add-code-mi…
…rror-to-file-diff-card Switch Admin Course Updates page to `CodeMirror`
- Loading branch information
Showing
15 changed files
with
196 additions
and
17 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
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,31 @@ | ||
import Controller from '@ember/controller'; | ||
import { action } from '@ember/object'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import EXAMPLE_DOCUMENTS, { DiffBasedExampleDocument } from 'codecrafters-frontend/utils/code-mirror-documents'; | ||
|
||
const OPTION_DEFAULTS = { | ||
forceDarkTheme: false, | ||
selectedDocumentIndex: 1, | ||
useCodeMirror: true, | ||
}; | ||
|
||
export default class DemoFileDiffCardController extends Controller { | ||
@tracked documents: DiffBasedExampleDocument[] = EXAMPLE_DOCUMENTS; | ||
|
||
@tracked forceDarkTheme: boolean = OPTION_DEFAULTS.forceDarkTheme; | ||
@tracked selectedDocumentIndex: number = OPTION_DEFAULTS.selectedDocumentIndex; | ||
@tracked useCodeMirror: boolean = OPTION_DEFAULTS.useCodeMirror; | ||
|
||
get selectedDocument() { | ||
return this.documents[this.selectedDocumentIndex] || DiffBasedExampleDocument.createEmpty(); | ||
} | ||
|
||
@action resetAllOptions() { | ||
Object.assign(this, OPTION_DEFAULTS); | ||
} | ||
|
||
@action selectedDocumentIndexDidChange(event: Event) { | ||
const target: HTMLSelectElement = event.target as HTMLSelectElement; | ||
this.selectedDocumentIndex = target.selectedIndex; | ||
} | ||
} |
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,17 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
const QUERY_PARAMS = ['forceDarkTheme', 'selectedDocumentIndex', 'useCodeMirror']; | ||
|
||
interface QueryParamOptions { | ||
[key: string]: { | ||
replace: boolean; | ||
}; | ||
} | ||
|
||
export default class DemoFileDiffCardRoute extends Route { | ||
queryParams = QUERY_PARAMS.reduce<QueryParamOptions>((acc, param) => { | ||
acc[param] = { replace: true }; | ||
|
||
return acc; | ||
}, {}); | ||
} |
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,3 @@ | ||
.course-admin-updates-diff-container code-mirror .cm-collapsedLines { | ||
margin-left: -24px; | ||
} |
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,50 @@ | ||
{{page-title "FileDiffCard"}} | ||
|
||
{{#let | ||
"flex flex-wrap text-sm font-semibold text-gray-600 dark:text-gray-200 border-b border-gray-200 dark:border-gray-700 | ||
py-2" | ||
"flex cursor-default select-none text-nowrap mx-2" | ||
as |groupClasses labelClasses| | ||
}} | ||
<component-options class="{{groupClasses}} -mt-8"> | ||
<component-options-left class="flex flex-grow flex-wrap"> | ||
<label class="{{labelClasses}}" title="File for the component to render (select a preset)"> | ||
<span class="mr-2">File:</span> | ||
<select class="dark:bg-gray-700" {{on "change" this.selectedDocumentIndexDidChange}}> | ||
{{#each this.documents as |doc index|}} | ||
<option selected={{eq this.selectedDocumentIndex index}}>{{doc.filename}} ({{doc.language}})</option> | ||
{{/each}} | ||
</select> | ||
</label> | ||
</component-options-left> | ||
<component-options-right class="flex flex-wrap"> | ||
<label class="{{labelClasses}}" title="Use CodeMirror instead of SyntaxHighlightedDiff for rendering the diff"> | ||
<Input @type="checkbox" @checked={{this.useCodeMirror}} /> | ||
<span class="ml-2">useCodeMirror</span> | ||
</label> | ||
<label class="{{labelClasses}}" title="Always render CodeMirror using Dark Theme"> | ||
<Input @type="checkbox" @checked={{this.forceDarkTheme}} /> | ||
<span class="ml-2">forceDarkTheme</span> | ||
</label> | ||
</component-options-right> | ||
</component-options> | ||
{{/let}} | ||
|
||
<FileDiffCard | ||
@useCodeMirror={{this.useCodeMirror}} | ||
@code={{this.selectedDocument.diff}} | ||
@filename={{this.selectedDocument.filename}} | ||
@language={{this.selectedDocument.language}} | ||
@forceDarkTheme={{this.forceDarkTheme}} | ||
class="mt-4 {{if this.forceDarkTheme 'dark'}}" | ||
/> | ||
|
||
<div class="my-2 text-right"> | ||
<span | ||
role="button" | ||
class="text-xs text-blue-600 hover:text-blue-800 dark:text-blue-200 dark:hover:text-blue-400 underline cursor-pointer" | ||
{{on "click" this.resetAllOptions}} | ||
>Reset all options</span> | ||
</div> | ||
|
||
{{outlet}} |
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