mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Stories: an entry for a deleted story drops its ?story= in any mode
Back or Forward into such an entry from Explore or an open story clears the story and its time from the address and the entry's history state, keeping the globe hash and, when the entry is Explore, Explore itself.
This commit is contained in:
1 parent
6904ce0e7a
commit
82475bced3
2 files changed
+62
-3
No files matched your search
@@ -183,6 +183,22 @@ export function createStoriesController({
|
||||
delete state.gevStories;
|
||||
history.replaceState(state, '', urlFor({}));
|
||||
}
|
||||
// Without the story of an entry whose story is gone.
|
||||
function dropMissingStory(params) {
|
||||
if (!params.has(PARAM_STORIES)) {
|
||||
clearStoriesUrl();
|
||||
return;
|
||||
}
|
||||
const url = new URL(location.href);
|
||||
url.searchParams.delete(PARAM_STORY);
|
||||
url.searchParams.delete(PARAM_STORY_TIME);
|
||||
const state = { ...(history.state ?? {}) };
|
||||
if (state.gevStories) {
|
||||
state.gevStories = { ...state.gevStories };
|
||||
delete state.gevStories.story;
|
||||
}
|
||||
history.replaceState(state, '', url);
|
||||
}
|
||||
// Steps back over Stories' entries; `landed` runs once the page Stories
|
||||
// opened from is current (or at once when Stories pushed nothing). A
|
||||
// traversal that never lands (cross-document, blocked) gives up after 2 s.
|
||||
@@ -258,6 +274,10 @@ export function createStoriesController({
|
||||
}
|
||||
const params = new URLSearchParams(location.search);
|
||||
const id = params.get(PARAM_STORY);
|
||||
// An entry for a story that is gone (deleted since) opens nothing, in
|
||||
// any mode; its ?story= must not stay in the address for the next share
|
||||
// link. The entry's own Explore and the globe hash stay.
|
||||
if (id && !storyById(id)) dropMissingStory(params);
|
||||
if (id && storyById(id))
|
||||
controller.openStory(id, {
|
||||
fromHistory: true,
|
||||
@@ -269,9 +289,6 @@ export function createStoriesController({
|
||||
: controller.backToExplore({ fromHistory: true, returningToExplore });
|
||||
else if (store.mode !== 'closed') controller.close({ fromHistory: true });
|
||||
else {
|
||||
// An entry for a story that is gone (deleted since) opens nothing;
|
||||
// its ?story= must not stay in the address for the next share link.
|
||||
if (id) clearStoriesUrl();
|
||||
if (pendingView) {
|
||||
// Another browser navigation landed while the scene was stopping.
|
||||
// The destination owns the globe now, so discard the earlier restore.
|
||||
|
||||
@@ -966,6 +966,48 @@ test('Back into the entry of a deleted story, with Stories closed, clears ?story
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
for (const [from, enter] of [
|
||||
['Explore', (controller) => controller.open()],
|
||||
['an open story', (controller) => controller.openStory('gev:flights-radar')],
|
||||
]) {
|
||||
test(`Back into the entry of a deleted story, from ${from}, clears ?story=`, () => {
|
||||
const { controller, store } = setup();
|
||||
enter(controller);
|
||||
assert.notEqual(store.mode, 'closed');
|
||||
history.replaceState(
|
||||
{ gevStories: { story: 'gev:gone', depth: 2, explore: 1 } },
|
||||
'',
|
||||
'/?story=gev%3Agone&storyTime=12#lat=1',
|
||||
);
|
||||
dispatchEvent(new PopStateEvent('popstate'));
|
||||
const url = new URL(location.href);
|
||||
assert.equal(url.searchParams.has('story'), false);
|
||||
assert.equal(url.searchParams.has('storyTime'), false);
|
||||
assert.equal(url.hash, '#lat=1', 'the globe state stays');
|
||||
assert.equal(history.state?.gevStories?.story, undefined);
|
||||
controller.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
test('Back into an Explore entry naming a deleted story keeps Explore', () => {
|
||||
const { controller, store } = setup();
|
||||
controller.openStory('gev:flights-radar');
|
||||
history.replaceState(
|
||||
{ gevStories: { story: 'gev:gone', depth: 1, explore: 1 } },
|
||||
'',
|
||||
'/?stories=explore&story=gev%3Agone#lat=1',
|
||||
);
|
||||
dispatchEvent(new PopStateEvent('popstate'));
|
||||
const url = new URL(location.href);
|
||||
assert.equal(url.searchParams.get('stories'), 'explore');
|
||||
assert.equal(url.searchParams.has('story'), false);
|
||||
assert.equal(url.hash, '#lat=1');
|
||||
assert.equal(history.state?.gevStories?.depth, 1);
|
||||
assert.equal(history.state?.gevStories?.story, undefined);
|
||||
assert.equal(store.mode, 'explore');
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
test('unsaved scenes appear as local drafts and disappear when deleted', () => {
|
||||
setActivePinia(createPinia());
|
||||
history.replaceState(null, '', '/');
|
||||
|
||||
Reference in new issue
Block a user