-
Notifications
You must be signed in to change notification settings - Fork 3
feat(friends): add searchable friend lists #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| <script setup lang="ts"> | ||
| import UserItem from './item.vue' | ||
| import { NGrid, NGi } from 'naive-ui' | ||
| import { ref } from 'vue' | ||
| import { ref, watch } from 'vue' | ||
| import type { RelationList } from '@services/../pl-serve-type-main/type/main' | ||
| import { getData } from '@services/api/getData.ts' | ||
| import { showAPiError } from '@popup/index.ts' | ||
|
|
@@ -24,10 +24,11 @@ import { showMessage } from '@popup/naiveui' | |
|
|
||
| // cols需要在父组件传参,这可能会在好友界面和Profile界面(未实现)展现 | ||
| // Props `cols` needs to be passed from the parent component, which may be displayed in the Friends page and Profile page (not implemented yet). | ||
| const { userid, type } = defineProps<{ | ||
| const { userid, type, query } = defineProps<{ | ||
| userid?: string | ||
| type?: string | ||
| cols?: number | ||
| query?: string | ||
| }>() | ||
|
|
||
| let loading = ref(false) | ||
|
|
@@ -53,7 +54,7 @@ async function handleLoad() { | |
| DisplayType: type ? Number(type) : 0, | ||
| Skip: skip.value, | ||
| Take: 24, | ||
| Query: '', | ||
| Query: query || '', | ||
| }) | ||
| if (getRelationsRes.Status !== 200) { | ||
| showAPiError(t('errors.apiErrorTitle'), t('errors.apiErrorMessage'), handleLoad) | ||
|
|
@@ -62,7 +63,7 @@ async function handleLoad() { | |
| DisplayType: type, | ||
| Skip: skip.value, | ||
| Take: 24, | ||
| Query: '', | ||
| Query: query || '', | ||
| }) | ||
| const _res = removeToken(getRelationsRes) | ||
| window.$ErrorLogger.captureApiError( | ||
|
|
@@ -92,6 +93,17 @@ window.$Logger.logPageView({ | |
| }) | ||
|
|
||
| handleLoad() | ||
|
|
||
| watch( | ||
| () => query, | ||
| () => { | ||
| items.value = [] | ||
| skip.value = 0 | ||
| noMore.value = false | ||
| hasInformed.value = false | ||
| void handleLoad() | ||
|
Comment on lines
+100
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the search query changes while a Useful? React with 👍 / 👎. |
||
| }, | ||
| ) | ||
| </script> | ||
|
|
||
| <style scoped></style> | ||
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.
If the user updates the search text while a previous
/Users/GetRelationsrequest is still in flight, this watcher clearsitemsand immediately callshandleLoad(), buthandleLoad()exits early becauseloading.valueis stilltrue. When the old request finally resolves, it appends results for the stale query, and no request for the new query is guaranteed to run, so the list can show incorrect search results until another scroll/load event happens.Useful? React with 👍 / 👎.