Skip to content

Commit ab3498f

Browse files
committed
fix: pasing diff in json format to route
1 parent ca91ee4 commit ab3498f

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

diff-match-patch.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'diff-match-patch'

pages/diff/_lhs/_rhs.vue renamed to pages/diff/_diff.vue

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="h-full">
3-
<main class="container h-full mx-auto mt-24">
3+
<main class="h-full mt-24 xl:container">
44
<div class="flex gap-4 mt-5">
55
<div
66
class="flex-1 p-4 overflow-y-auto border-2 rounded-sm max-h-screen--nav"
@@ -22,24 +22,12 @@
2222
</template>
2323

2424
<script>
25-
import DiffMatchPatch from 'diff-match-patch'
26-
import { urlDecode } from '../../../helpers/utils'
27-
const dmp = new DiffMatchPatch()
25+
import { urlDecode } from '../../helpers/utils'
2826
export default {
2927
layout: 'main',
30-
lhs: '',
31-
rhs: '',
32-
diff: [],
3328
mounted() {
34-
const { lhs, rhs } = this.$route.params
35-
this.originalLhs = urlDecode(lhs).split('\n')
36-
this.originalRhs = urlDecode(rhs).split('\n')
37-
const diff = this.originalLhs.map((x, i) => {
38-
if (!this.originalRhs[i]) {
39-
this.originalRhs[i] = ''
40-
}
41-
return dmp.diff_main(x, this.originalRhs[i])
42-
})
29+
const { diff: _diff } = this.$route.params
30+
const diff = JSON.parse(urlDecode(_diff))
4331
this.lhsDiff = diff
4432
.map((lineDiff) => {
4533
return lineDiff
@@ -71,9 +59,6 @@ export default {
7159
},
7260
data() {
7361
return {
74-
diff: this.diff,
75-
originalRhs: this.originalRhs,
76-
originalLhs: this.originalLhs,
7762
lhsDiff: this.lhsDiff,
7863
rhsDiff: this.rhsDiff,
7964
}

pages/index.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="h-full">
3-
<main class="container h-full mx-auto mt-24">
3+
<main class="h-full mt-24 xl:container">
44
<form @submit="checkForm" class="w-full h-full">
55
<div class="flex flex-wrap w-full h-full gap-4">
66
<textarea
@@ -25,8 +25,10 @@
2525
</template>
2626

2727
<script lang="ts">
28+
import DiffMatchPatch from 'diff-match-patch'
2829
import Vue from 'vue'
2930
import { urlEncode } from '../helpers/utils'
31+
const dmp = new DiffMatchPatch()
3032
export default Vue.extend({
3133
layout: 'main',
3234
methods: {
@@ -40,8 +42,17 @@ export default Vue.extend({
4042
'rhs'
4143
) as HTMLTextAreaElement
4244
const rhs: string = rhsTextArea?.value || ''
45+
46+
const originalLhs = lhs.split('\n')
47+
const originalRhs = rhs.split('\n')
48+
const diff = originalLhs.map((x, i) => {
49+
if (!originalRhs[i]) {
50+
originalRhs[i] = ''
51+
}
52+
return dmp.diff_main(x, originalRhs[i])
53+
})
4354
this.$router.push({
44-
path: `/diff/${urlEncode(lhs)}/${urlEncode(rhs)}`,
55+
path: `/diff/${urlEncode(JSON.stringify(diff))}`,
4556
})
4657
},
4758
},

tailwind.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ module.exports = {
33
theme: {
44
maxHeight: {
55
'screen--nav': 'calc(100vh - 7rem)',
6-
}
6+
},
7+
container: {
8+
center: true,
9+
},
710
},
811
plugins: [
912
require('@tailwindcss/forms'),

0 commit comments

Comments
 (0)