Skip to content

Commit

Permalink
Merge pull request #24115 from rashidshamloo/bugfix-23723-canvas-link…
Browse files Browse the repository at this point in the history
…-shows-default-story-on-mobile

Manager: Update `store.settings.lastTrackedStoryId`
  • Loading branch information
JReinhold authored Oct 24, 2023
2 parents 58b6b0a + b6acefa commit fd539a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions code/lib/manager-api/src/modules/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ export const init: ModuleFn<SubAPI, SubState> = ({

if (!entry) throw new Error(`Unknown id or title: '${titleOrId}'`);

store.setState({
settings: { ...store.getState().settings, lastTrackedStoryId: entry.id },
});

// We want to navigate to the first ancestor entry that is a leaf
const leafEntry = api.findLeafEntry(hash, entry.id);
const fullId = leafEntry.refId ? `${leafEntry.refId}_${leafEntry.id}` : leafEntry.id;
Expand Down
10 changes: 10 additions & 0 deletions code/lib/manager-api/src/tests/stories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,16 @@ describe('stories API', () => {
api.selectStory('intro');
expect(navigate).toHaveBeenCalledWith('/docs/intro--docs');
});
it('updates lastTrackedStoryId', () => {
const initialState = { path: '/story/a--1', storyId: 'a--1', viewMode: 'story' };
const moduleArgs = createMockModuleArgs({ initialState });
const { api } = initStories(moduleArgs as unknown as ModuleArgs);
const { store } = moduleArgs;

api.setIndex({ v: 4, entries: navigationEntries });
api.selectStory('a--1');
expect(store.getState().settings.lastTrackedStoryId).toBe('a--1');
});
describe('deprecated api', () => {
it('allows navigating to a combination of title + name', () => {
const initialState = { path: '/story/a--1', storyId: 'a--1', viewMode: 'story' };
Expand Down

0 comments on commit fd539a7

Please sign in to comment.