Skip to content

Commit

Permalink
Use a queue for changes to about text
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis committed Nov 5, 2023
1 parent a81f241 commit 21b927f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions api/queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class PromiseQueue {
// happen.
const quizQueue = new PromiseQueue();

const aboutQueue = new PromiseQueue();

export {
aboutQueue,
quizQueue,
};
18 changes: 11 additions & 7 deletions components/profile-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
} from '../env/env';
import * as _ from "lodash";
import debounce from 'lodash/debounce';
import { aboutQueue } from '../api/queue';

const formatHeight = (og: OptionGroup<OptionGroupInputs>): string | undefined => {
if (!isOptionGroupSlider(og.input)) return '';
Expand Down Expand Up @@ -155,19 +156,22 @@ const ProfileTab_ = ({navigation}) => {
);
};

const enqueueAbout = async (about: string, cb: (ok: boolean) => void) => {
aboutQueue.addTask(
async () => {
const response = await japi('patch', '/profile-info', { about });
cb(response.ok);
}
);
};

const AboutPerson = ({navigation, data}) => {
const [aboutState, setAboutState] = useState<
'unchanged' | 'saving...' | 'saved' | 'error'
>('unchanged');

const debouncedOnChangeAboutText = useCallback(
debounce(
async (about: string, cb: (ok: boolean) => void) => {
const response = await japi('patch', '/profile-info', { about });
cb(response.ok);
},
1000,
),
debounce(enqueueAbout, 1000),
[]
);

Expand Down

0 comments on commit 21b927f

Please sign in to comment.