Skip to content

Commit

Permalink
fix(tools): search all cases in finder and swapper counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed May 8, 2022
1 parent cf70d09 commit 84c2ff8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,17 @@
{{ finder.state.actuallyLetterCounter }} /
{{ finder.state.maxLetterCounter }}
</div>
<HeroIcon class="text-2xs ml-2 wb-icon" @click="finder.onUp">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M5.293 7.707a1 1 0 010-1.414l4-4a1 1 0 011.414 0l4 4a1 1 0 01-1.414 1.414L11 5.414V17a1 1 0 11-2 0V5.414L6.707 7.707a1 1 0 01-1.414 0z"
clip-rule="evenodd"
/>
</svg>
</HeroIcon>
<HeroIcon class="text-2xs wb-icon" @click="finder.onDown">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M14.707 12.293a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 111.414-1.414L9 14.586V3a1 1 0 012 0v11.586l2.293-2.293a1 1 0 011.414 0z"
clip-rule="evenodd"
/>
</svg>
</HeroIcon>
<IconUp
class="text-2xs ml-2 wb-icon h-5 w-5"
@click="finder.onUp"
/>
<IconDown class="text-2xs wb-icon h-5 w-5" @click="finder.onDown" />
</div>
<div>
<HeroIcon class="text-2xs wb-icon" @click.prevent="onClose">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clip-rule="evenodd"
/>
</svg>
</HeroIcon>
<IconClose
class="text-2xs wb-icon h-5 w-5"
@click.prevent="onClose"
/>
</div>
</div>
<input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,97 +12,25 @@
<div
class="flex items-center justify-between w-full mb-1 cursor-pointer"
>
<div>
<HeroIcon
:class="[
switcher.state.equal
? 'border border-theme-editor-extras-switcher-border'
: '',
]"
class="text-2xs wb-icon"
@click.prevent="switcher.state.equal = !switcher.state.equal"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
d="M8.707 7.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l2-2a1 1 0 00-1.414-1.414L11 7.586V3a1 1 0 10-2 0v4.586l-.293-.293z"
/>
<path
d="M3 5a2 2 0 012-2h1a1 1 0 010 2H5v7h2l1 2h4l1-2h2V5h-1a1 1 0 110-2h1a2 2 0 012 2v10a2 2 0 01-2 2H5a2 2 0 01-2-2V5z"
/>
</svg>
</HeroIcon>
<HeroIcon
class="text-2xs wb-icon mx-1"
@click="switcher.onSwitcherAll"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M3 3a1 1 0 00-1 1v12a1 1 0 102 0V4a1 1 0 00-1-1zm10.293 9.293a1 1 0 001.414 1.414l3-3a1 1 0 000-1.414l-3-3a1 1 0 10-1.414 1.414L14.586 9H7a1 1 0 100 2h7.586l-1.293 1.293z"
clip-rule="evenodd"
/>
</svg>
</HeroIcon>
</div>
<div class="flex items-center">
<div class="font-poppins">
{{ switcher.state.actuallyLetterCounter }} /
{{ switcher.state.maxLetterCounter }}
</div>
<HeroIcon class="text-2xs ml-2 wb-icon" @click="switcher.onUp">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M5.293 7.707a1 1 0 010-1.414l4-4a1 1 0 011.414 0l4 4a1 1 0 01-1.414 1.414L11 5.414V17a1 1 0 11-2 0V5.414L6.707 7.707a1 1 0 01-1.414 0z"
clip-rule="evenodd"
/>
</svg>
</HeroIcon>
<HeroIcon class="text-2xs wb-icon" @click="switcher.onDown">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M14.707 12.293a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 111.414-1.414L9 14.586V3a1 1 0 012 0v11.586l2.293-2.293a1 1 0 011.414 0z"
clip-rule="evenodd"
/>
</svg>
</HeroIcon>
<IconUp
class="text-2xs ml-2 wb-icon h-5 w-5"
@click="switcher.onUp"
/>
<IconDown
class="text-2xs wb-icon h-5 w-5"
@click="switcher.onDown"
/>
</div>
<div>
<HeroIcon class="text-2xs wb-icon" @click.prevent="onClose">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clip-rule="evenodd"
/>
</svg>
</HeroIcon>
<IconClose
class="text-2xs wb-icon h-5 w-5"
@click.prevent="onClose"
/>
</div>
</div>
<input
Expand Down
14 changes: 9 additions & 5 deletions packages/better-write-app/src/use/tools/finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ export const useFinder = () => {

PROJECT.pages.forEach((context: ContextState) => {
context.entities.forEach((entity: Entity) => {
if (!state.entry) return
const raw = entity.raw.split(' ')

if (entity.raw.includes(state.entry)) {
state.listOfLettersExists.push({ entity, page: context })
state.maxLetterCounter++
}
raw.forEach((word) => {
if (!state.entry) return

if (word.includes(state.entry)) {
state.listOfLettersExists.push({ entity, page: context })
state.maxLetterCounter++
}
})
})
})

Expand Down
46 changes: 20 additions & 26 deletions packages/better-write-app/src/use/tools/switcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,17 @@ export const useSwitcher = () => {
// TODO: Deletar em caso de output vazio
if (!entry) return

arr.forEach((e: Entity) => {
const text = e.raw.split(' ')

text.forEach((t: string) => {
if (equal && t === entry) {
storage.normalize().then(() => {
CONTEXT.switchEntityRaw({
entity: e,
match: t,
raw: output,
})
arr.forEach((entity: Entity) => {
// all cases
if (entry === entity.raw) {
storage.normalize().then(() => {
CONTEXT.switchEntityRaw({
entity,
match: entry,
raw: output,
})
} else if (!equal && t.includes(entry)) {
storage.normalize().then(() => {
CONTEXT.switchEntityRaw({
entity: e,
match: entry,
raw: output,
})
})
}
})
})
}
})
}

Expand All @@ -75,12 +64,17 @@ export const useSwitcher = () => {

PROJECT.pages.forEach((context: ContextState) => {
context.entities.forEach((e: Entity) => {
if (!state.entry) return
const raw = e.raw.split(' ')

raw.forEach((word) => {
console.log(word)
if (!state.entry) return

if (e.raw.includes(state.entry)) {
state.listOfLettersExists.push({ entity: e, page: context })
state.maxLetterCounter++
}
if (word.includes(state.entry)) {
state.listOfLettersExists.push({ entity: e, page: context })
state.maxLetterCounter++
}
})
})
})

Expand Down

0 comments on commit 84c2ff8

Please sign in to comment.