-
Notifications
You must be signed in to change notification settings - Fork 63
TS-ify use-load-more and use TS and defineComponent in layouts and pages #1473
Conversation
Storybook and Tailwind configuration previews: Ready Storybook: https://wordpress.github.io/openverse-frontend/1473 Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again. You can check the GitHub pages deployment action list to see the current status of the deployments. |
Size Change: +85 B (0%) Total Size: 1.44 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I'd prefer using toRef
for those computeds but not a blocker.
src/pages/search/audio.vue
Outdated
@@ -72,8 +72,8 @@ export default defineComponent({ | |||
focusFilters.focusFilterSidebar(event, Focus.Last) | |||
} | |||
} | |||
|
|||
const { canLoadMore, onLoadMore } = useLoadMore(props) | |||
const searchTermRef = computed(() => props.searchTerm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW you can also use toRef
for this. I think it might convey the intention a little more clearly than compute:
const searchTermRef = computed(() => props.searchTerm) | |
const searchTermRef = toRef(props, 'searchTerm') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I finally understood what toRef
is used for! :)
src/pages/search/image.vue
Outdated
@@ -25,7 +25,9 @@ export default defineComponent({ | |||
useMeta({ title: `${props.searchTerm} | Openverse` }) | |||
|
|||
const results = computed(() => props.resultItems.image) | |||
const { canLoadMore, onLoadMore } = useLoadMore(props) | |||
|
|||
const searchTermRef = computed(() => props.searchTerm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const searchTermRef = computed(() => props.searchTerm) | |
const searchTermRef = toRef(props, 'searchTerm') |
src/pages/search/index.vue
Outdated
@@ -17,7 +17,9 @@ export default defineComponent({ | |||
setup(props) { | |||
useMeta({ title: `${props.searchTerm} | Openverse` }) | |||
|
|||
const { canLoadMore, onLoadMore } = useLoadMore(props) | |||
const searchTermRef = computed(() => props.searchTerm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const searchTermRef = computed(() => props.searchTerm) | |
const searchTermRef = toRef(props, 'searchTerm') |
@@ -72,7 +72,7 @@ | |||
</VContentPage> | |||
</template> | |||
|
|||
<script> | |||
<script lang="ts"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include this page and the others in the tsconfig.json
file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question, @krysal !
If we include this page in tsconfig
, then it will be typechecked. And if the types are incorrect, it will not build the app. And because we have some dependencies on Aria-kit that uses some React types internally, we cannot typecheck many of the pages/components that have popups or modals in them.
When we only add lang="ts"
, but do not add the files to tsconfig
, we can use Typescript in the code, but type errors will not prevent the app from building. So, we can use the TS type annotations and declare types instead of using the JSDoc comments in these components. I feel it is easier to read the code when all components use the same type annotation style, you don't have to context-switch as much.
# Conflicts: # src/pages/index.vue
Fixes
Related to Typescriptification milestone
Description
This PR is extracted from #1405 to make it easier to review.
This PR refactors useLoadMore composable so that it's easier to see what arguments it expects.
It also adds
lang="ts"
anddefineComponent
to pages and layouts.Testing Instructions
Passing CI should be fine.
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin