Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
add force refresh button
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Sep 29, 2022
1 parent b62dc9d commit f160fd9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/structures/ThreadPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import React, { useContext, useEffect, useRef, useState } from 'react';
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
import { EventTimelineSet } from 'matrix-js-sdk/src/models/event-timeline-set';
import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread';
import { Room } from 'matrix-js-sdk/src/models/room';
Expand Down Expand Up @@ -230,6 +230,7 @@ const ThreadPanel: React.FC<IProps> = ({

useEffect(() => {
if (timelineSet && !Thread.hasServerSideSupport) {
timelineSet.resetLiveTimeline();
timelinePanel.current.refreshTimeline();
}
}, [timelineSet, timelinePanel]);
Expand All @@ -240,6 +241,14 @@ const ThreadPanel: React.FC<IProps> = ({
});
} : null;

const forceRefresh = useCallback(async () => {
console.error("forceRefresh");
timelineSet.resetLiveTimeline();
room.resetLiveTimeline();
await room.fetchRoomThreads();
timelinePanel?.current.refreshTimeline();
}, [room, timelineSet]);

return (
<RoomContext.Provider value={{
...roomContext,
Expand Down Expand Up @@ -278,6 +287,7 @@ const ThreadPanel: React.FC<IProps> = ({
sensor={card.current}
onMeasurement={setNarrow}
/>
<button onClick={forceRefresh}>Refresh</button>
{ timelineSet
? <TimelinePanel
key={timelineSet.getFilter()?.filterId ?? (roomId + ":" + filterOption)}
Expand Down

0 comments on commit f160fd9

Please sign in to comment.