Skip to content

Commit

Permalink
Merge pull request #45 from hamachi25:await-get-mute-settings
Browse files Browse the repository at this point in the history
intersection observerによるミュート設定の読み込みを改善
  • Loading branch information
hamachi25 authored Mar 4, 2025
2 parents 3a4709c + 2ee2c7b commit 5861abf
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/entrypoints/content/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,20 @@ const App = () => {
const userWorks = useRef<UserWorks>({}); // ユーザーの作品一覧
const workTag = useRef<WorkTag | undefined>(undefined);
const page = useRef(2);
const inView = useRef(false);

const muteSettings = useContext(MuteContext);

// Intersection Observer発火後にmuteSettingsが読み込まれた場合
useEffect(() => {
(async () => {
if (muteSettings.tags[0] !== "null" && inView.current) {
await firstPageRequest();
await loadMore();
}
})();
}, [muteSettings.tags]);

const loadMore = async () => {
if (hasMore === undefined) return;

Expand Down Expand Up @@ -255,8 +266,9 @@ const App = () => {

const { ref } = useInView({
rootMargin: "50% 0px",
onChange: async (inView) => {
if (inView) {
onChange: async (isInView) => {
inView.current = isInView;
if (isInView && muteSettings.tags[0] !== "null") {
await firstPageRequest();
await loadMore();
}
Expand Down

0 comments on commit 5861abf

Please sign in to comment.